http://qs1969.pair.com?node_id=233210

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

Replies are listed 'Best First'.
Re: Trying to learn something about obfuscation
by gmax (Abbot) on Feb 06, 2003 at 20:19 UTC
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 Mr. Muskrat (Canon) 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 :)