Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Some everyday code.

by iamcal (Friar)
on Jun 17, 2001 at 17:53 UTC ( [id://89164]=note: print w/replies, xml ) Need Help??


in reply to Some everyday code.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://89164]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-06-17 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.