Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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. :-)

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; }

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://565265]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2017-02-26 20:43 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.