<html> Ok heres some of my EVERYDAY code. I friend of mine suggested I post it here. As he didnt think it was very human readable. I figured its a pretty good example of how NOT to do something.
#!/usr/bin/perl $t=("wrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongway" +);@j=(83,13,11,16,-61,3,60,-4,-63,60,1,-23,25,-43,-23,55,-11,-53,45,- +59,77,1,10,-5);my $c=("wrongway yes i said wrongway who else ?");$m=0 +;for ($y=0;$y<$#j+1;$y++){$m=$m+$j[$y];push(@r,$m);print chr ord chr( +ord(substr($t,$y+3,1))^ord(chr($r[$y]))^ord chr ord chr ord(chr(ord(s +ubstr($c,$y,1)))));}print " - ". substr($c,20,8);sleep $j[5];
WrongWay

Replies are listed 'Best First'.
Re: Some everyday code.
by iamcal (Friar) on Jun 17, 2001 at 17:53 UTC
    How to break down this obstufication...

    First break it up into readable code:

    #!/usr/bin/perl $t=("wrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongway" +); @j=(83,13,11,16,-61,3,60,-4,-63,60,1,-23,25,-43,-23,55,-11,-53,45,-59, +77,1,10,-5); my $c=("wrongway yes i said wrongway who else ?"); $m=0; for ($y=0;$y<$#j+1;$y++){ $m=$m+$j[$y]; push(@r,$m); print chr ord chr(ord(substr($t,$y+3,1))^ord(chr($r[$y]))^ord chr +ord chr ord(chr(ord(substr($c,$y,1))))); } print " - ". substr($c,20,8); sleep $j[5];
    Next we'll cancel out the redundant pairs of chr & ord and remove the (annoying) sleep

    #!/usr/bin/perl $t=("wrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongway" +); @j=(83,13,11,16,-61,3,60,-4,-63,60,1,-23,25,-43,-23,55,-11,-53,45,-59, +77,1,10,-5); my $c=("wrongway yes i said wrongway who else ?"); $m=0; for ($y=0;$y<$#j+1;$y++){ $m=$m+$j[$y]; push(@r,$m); print chr( ord(substr($t,$y+3,1)) ^ $r[$y] ^ ord(substr($c,$y,1)) +); } print " - ". substr($c,20,8);
    And now we notice that @r is redundant:

    #!/usr/bin/perl $t=("wrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongwaywrongway" +); @j=(83,13,11,16,-61,3,60,-4,-63,60,1,-23,25,-43,-23,55,-11,-53,45,-59, +77,1,10,-5); my $c=("wrongway yes i said wrongway who else ?"); $m=0; for ($y=0;$y<$#j+1;$y++){ $m=$m+$j[$y]; print chr( ord(substr($t,$y+3,1)) ^ $m ^ ord(substr($c,$y,1)) ); } print " - ". substr($c,20,8);
    And the code is now pretty obvious. Loop through @j using a for loop on $y. Increment $m by the current value from @j, then XOR a character from $t, one from $c and the current value of $m. Then finally print out a sub string of $c.