[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] JAPH gone mad...



At 13:15 8/6/99 +0000, John Carter wrote:

>The recent Shuffling thread and also the obfusticated perl contest
>caused some of my neurons to misfire along these paths...
>
>1. Self replicating programs have long been a subject of fun.
>
>2. Encoding information in the whitespace of a self analysing program
>   is another, not uncommon, fun way of producing JAPH's.
>
>My idea is the following. To write a program to build another program
>called A.
>
>Program A is a random number generator that has a special
>trajectory. Program A must read itself as its "seed" number, produce
>a couple of million other random numbers, computing a 32 bit checksum
>on each random number and halting and "eval"ing the first "random"
>number whose checksum matches a certain value. 

I did this before, although by brute force.  I also posted the code before,
but got zero responses to it -- not unsurprising, it was just obfuscated
code paste.

Here it is again, but it's doing some of what you talk about.

Here's the code.

#forthrase
sub r
{$m=2147483647;$q=127773;$a=16807;$r=2836;$h=$s1/$q;$l=$s1%$q;$t=$a*$l-$r*$h;
if($t>0){$s1=$t}else{$s1=$t+$m}}
$s1=$s2=44;$l2=1;@c=qw(163 19 54 570 330 221 7 361 255 164 164 115 
                       266 330 361 19 231 9 255 33 62 570 7 263 263);

for (my $l=0;$l<$#c;$l++)
{
  &r($l2++)while($l2<=($c[$l])-1);
  $b .=chr(&r($l2) % 256);$s1=$s2;$l2=1;
}  
eval(lc($b));

*
*
*
* Explanation follows (might pay to try to work out what's going on first,
otherwise
*                      it prolly isn't going to be much 'fun')
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

The subroutine 'r' is a random number generator, converted from Fortran
source to perl.  It generates the same random numbers if you run it on linux
or win32 (as opposed to rand(), which even with the same seed, produces
different numbers on different machines, as I found out when I first did this.)

The array @c is the code to run.  It is simply 'printf"hello_thrase"', but
the encoding is the interesting bit.

The code itself calls the random number generator 'n' times.  After '$c[n]'
calls, the letter produced from the random number generator is shoved into a
string.  Working through the @c array, each letter is 'randomly' computed,
and when eval'd produces the desired print string.

To create the original @c, I first had to create a program which would
generate UNIQUE random numbers for each ascii character, and record how many
times the random number generator needed to be called to produce that
letter/digit.  Once I had that table, I could create whatever "code" I
wanted to, all done apparently by random numbers. (See end of this post)

It seemed obfuscated to me when I created it, and I felt a bit tricky --
after seeing the FWP list for the past few weeks, I have no doubt that I am
a perl neophyte. :-)  Perhaps even neophyte is too strong a term.

Here's the raw (totally!) code I used to generate the original 'random
numbers'  Please, this code isn't at all nice, I just used it to create what
I needed at the time, so 'funwithperl' optimisations are not applicable to
this mess :-)

#catudobfus!
#
$s1=$s2=44;$m=2147483647;$q=127773;$a=16807;$r=2836;
$timestart = time();
$rused = {};
$b={};
my $repcount = 0;
my @c = ();
my @b = qw(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  0  0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 );
my @a = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6
7 8 9 ~ ! @ #
 $ % ^ & * \( \) _ + | { } ] [ ' ; / . , < > - \\ " = );  # last * is a
nasty kludge

push @a, ' '; push @a, 'Z'; push @a, 'Q';

print "array a is @a\n";
print "array b is @b\n";
print "array c is @c\n";

print "$#a\n";
for (my $loop = 0; $loop < $#a; $loop++)
{

  ++$repcount;
  if (($repcount % 1000) == 999) {print "."};
  if (($repcount % 100000) == 99999) {print "blah, failed"; last};
  $tempr = (r() % 256);
 
  redo if (chr($tempr) ne $a[$loop]);
  redo if (($rused{$tempr}) == 1);
  $rused{$tempr} = 1;
  $b[$loop] = $tempr;
  $c[$loop] = $repcount;
  $repcount = 0;
  $s1=$s2;
}

$timeend = time();
$runtime = $timeend - $timestart;
print "achieved in $runtime seconds\n";
print "array a is @a\n";
print "array b is @b\n";
print "array c is @c\n";


sub r
{
    $h=$s1/$q;$l=$s1%$q;$t=$a*$l-$r*$h;if($t>0){$s1=$t}else{$s1=$t+$m};
    return $s1;
}

__END__

Dac

__
Andrew Clayton   ******************************* News: "Excession"
dac@pcug.org.au  * http://www.pcug.org.au/~dac *  IRC: "DizietSma"
"What's this do?"*******************************  ICQ: 686 2357 



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe