Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Can someone please break this obfuscated code down for me

by VSarkiss (Monsignor)
on Aug 02, 2006 at 17:08 UTC ( #565265=note: print w/ replies, xml ) Need Help??


in reply to Can someone please break this obfuscated code down for me

BrowserUK has given you the best general tip above. If you're still wondering how that string turns into that program, an editor with syntax highlighting can help. Here's a breakdown if you still need it.

If you add some white space, you'll see the line looks like:

'' =~ ( '(?{' . ( '+]).][' ^ '[/@@){' ) . '"' . ( '^@@;.|' ^ '?,,^@^' ) . ',$/})' )
So it's matching the empty string against some bizarre pattern. The pattern is built up from concatenating five pieces, three of which are constants:
  • '(?{'
  • '"'
  • ',$/})'

The other two parts are wrapped in parentheses, and are the result of combining two strings with the exclusive-or operator (^, perlop for more info). Since the parts are constant, perl evaluates them at compile time. If you test it, you'll see that the first expression evaluates to print and the second to allen".

So now you see how Deparse got that string. If you haven't seen the ?{...} construct in Perl regular expressions, take a look at perlre. It allows you to execute code inside a regular expression. In this case it executes the code print "allen",$/.

QED. HTH. :-)

Update
If you want to really get a handle on how the exclusive-or operates to generate the string, it's best to look at the bits-n-bytes level. Try running this little snippet to see.

my @s = ( '+', ']', ')', '.', ']', '[', '[', '/', '@', '@', ')', '{', ); for (my $i = 0; $i < 6; $i++) { my ($l, $r) = ($s[$i], $s[$i+6]); printf "%s %x ^ %s %x = %s %x\n", $l, ord $l, $r, ord $r, $l ^ $r, ord $l ^ ord $r; }


Comment on Re: Can someone please break this obfuscated code down for me
Select or Download Code
Re^2: Can someone please break this obfuscated code down for me
by Burak (Chaplain) on Aug 02, 2006 at 19:34 UTC
    Excellent explanation :) and the code is really interesting...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-07-28 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls