(. This is an atempt to demystify the black art of perl obfuscation. Below is a commented and indented version of an obfuscated perl script. Hopefully, it will be clear to you all how it works. This is actually one of the very few obfuscated perl scripts which depends on the hash-key insertion ordering. What does that mean ? Well, if the insertion of the keys in the hash in the second do-block was rearanged to: { crackers => "rekc", queen => "lr" } then the code would no longer output the expected result.

Well, enough psychobabbling from me, here is the unobfuscated obfuscated perl script... .)

Enjoy,
Autark

#!perl -l # The use of perl special variables are very popular in obfuscation. # This will put spaces between each element of a printed list. # For other strange perl variables see the perlvar manpage. $, = " "; # Using implicit returns values and seldom used constructs adds to # the obfuscation. 'do' just returns the last value interpreted, # which happens to be a hash reference. $ja = do { # A hash with the words "just", "another" as hash values (only # reversed). { typehighs => "rehtona", noh_art => "tsuj" } }; $ph = do { # A hash with the words "cker", "rl" as hash values (only # reversed). # "cker" -> "ha" + "cker" = "hacker" # "rl" -> "pe" + "rl" = "perl" { queen => "lr", crackers => "rekc" } }; # Append the missing characters for the strings "lr" and "rekc". # This is done by using certain characteristics in the ja-hash keys $ph->{crackers} .= join("", $ph, map { substr($_, 4,1) } keys %$ja); $ph->{queen} .= join("", map { substr($_, 0,3) } keys %$ja); # Use of map and grep always confuse people. Use the default # variable as much as possible. Since all our values are # reversed, we first have to reverse each of them, as a # finishing touch, we uppercase the first letter in each word print map { ucfirst reverse } map { grep { defined } values %$_ } $ja,$ph;

In reply to Unobfuscated obfuscated perl course by autark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.