pysome has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
When i am playing a game,i came across three-line Perl code like:
($;,$_,$|,$\)=("Yoo*se\x7F*cd*Mcpk+"," "x17,1,"\r"); {vec($_=>1+$"=>$^F<<$^F)=ord($/^substr$;=>$"=int rand 16=>1); print&&select$,,$,,$,,$|/($|+tr/ //c);redo if y/ //>$^F**2};

It is so cool and hard understanding.Can anyone explain its detail for me ?Thanks

Replies are listed 'Best First'.
Re: Pls help me understand the obfuscated code
by EvanCarroll (Chaplain) on Aug 20, 2007 at 03:48 UTC
    Not sure if this helps but it is a good place to start
    ecarroll@x60s:~/code/perl/obfu$ perl -MO=Deparse ./test ($;, $_, $|, $\) = ("Yoo*se\177*cd*Mcpk+", ' ' x 17, 1, "\r"); { vec($_, 1 + $", $^F << $^F) = ord($/ ^ substr($;, $" = int rand 16 +, 1)); select $,, $,, $,, $| / ($| + tr/ /\000-\037!-\377/c) if print $_; redo if tr/ // > $^F ** 2; }
    I think you're also going to want to perldoc all those variables (that he isn't getting in the first statement) for their defaults. I don't think he is doing anything (too) special with them. Some of it is easily reduced.


    Evan Carroll
    www.EvanCarroll.com
Re: Pls help me understand the obfuscated code
by moklevat (Priest) on Aug 20, 2007 at 20:23 UTC
    Here is the code moderately de-obfuscated (not necessarily Perl Best Practices compliant):

    use strict; use warnings; ## Some characters to work with my $data = "Yoo*se\x7F*cd*Mcpk+"; ## Put 17 spaces in the default variable $_ = " " x 17 ; ## Force flush after every print $| = 1; ## Set record-separator to carriage return not newline $\ = "\r"; ## Other notes on the obfuscated code ## $^F is equal to 2 ## replaced => with comma ## ord($/ ^ $character) "decodes" the characters from $data { my $index = int( rand( 16)); my $character = substr( $data, $index, 1); my $decimal = ord($/ ^ $character); ## convert $decimal to its ascii equivalent and ## insert it into the string held in $_ vec($_ , 1 + $index , 8)= $decimal; ## print the contents of $_ with a delay = 1/(1+tr/ //c) print &&select(undef,undef,undef,1/(1+tr/ //c)); ## Rerun block if there are more than 4 spaces left redo if tr/ // > 4 }
Re: Pls help me understand the obfuscated code
by moklevat (Priest) on Aug 20, 2007 at 13:38 UTC
    Incidentally, this is one of the early-level puzzles from rankk.org.

    Update: It looks like this particular form of obfuscation can be traced to a japh style of Abigail's that turned up on cpan.

Re: Pls help me understand the obfuscated code
by TOD (Friar) on Aug 20, 2007 at 06:22 UTC
    the output is: "See you in Giza!" :D
    --------------------------------
    masses are the opiate for religion.