Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Trying to learn something about obfuscation

by Bismark (Scribe)
on Feb 06, 2003 at 18:06 UTC ( #233210=perlquestion: print w/ replies, xml ) Need Help??
Bismark has asked for the wisdom of the Perl Monks concerning the following question:

I'll admit that I am probably getting way ahead of myself, but I have been looking at some of the obfuscation and some of it is just driving me crazy. Would someone please give me some hints as to how the following code could print out JaPh? I understand how it is printing, just do not see where the letters are coming from.
die$;!~y//.-~/c.$;.([$^=~/./g]&~$").$&.($;&{}).$/
Kerry
"Yet what are all such gaieties to me
Whose thoughts are full of indices and surds?"
quotes the Lama

Comment on Trying to learn something about obfuscation
Download Code
Re: Trying to learn something about obfuscation
by Mr. Muskrat (Abbot) on Feb 06, 2003 at 18:42 UTC

    Start by breaking it down. Remember that y/// is the same as tr///.

    Looking at perlvar we see that $; is $SUBSCRIPT_SEPARATOR, $^ is $FORMAT_TOP_NAME, $" is $LIST_SEPARATOR, $& is $MATCH and $/ is $INPUT_RECORD_SEPARATOR.

    So what do we have now?

    use English; die $SUBSCRIPT_SEPARATOR!~tr//.-~/c.$SUBSCRIPT_SEPARATOR. ([$FORMAT_TOP_NAME=~/./g]&~$LIST_SEPARATOR). $MATCH.($SUBSCRIPT_SEPARATOR&{}).$INPUT_RECORD_SEPARATOR

    That should as clear as mud :)

Re: Trying to learn something about obfuscation
by rob_au (Abbot) on Feb 06, 2003 at 18:55 UTC
    In addition to the direction provided by Mr. Muskrat above, I would also point you to assistance which the perl compiler itself can provide when deciphering obfuscated code. For example, using the Deparse backend, a parsed version of the code can be generated which is invariably much more readable:

    rob@kathmandu:~$ perl -MO=Deparse -e 'die$;!~y//.-~/c.$;.([$^=~/./g]&~ +$").$&.($;&{}).$/' die !($; =~ tr//.-~/c) . $; . ([$^ =~ /./g] & ~$") . $& . ($; & {}) . +$/; -e syntax OK

    Note though that some code can be written to deliberately not be able to be parsed in this manner. The joy of obfuscation.

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000101011"))'

Re: Trying to learn something about obfuscation
by gmax (Abbot) on Feb 06, 2003 at 20:19 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-09-21 17:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (173 votes), past polls