Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I was also surprised that $ = was legal. Unfortunately,

perl -MO=Deparse

spoiled that fun, as well as teaching me to look out for that in the future :)

Being thoroughly impressed by this (as well as the rest of liverpole's JAPH's, I thougt I'd go ahead and post a detailed de-obfuscation of this particularly clever (to me, at least) JAPH.

First, the obfuscated code:

#!/usr/bin/perl + $ == _ eq _; $ -= ( ) = qw; ( );; $ *= $ -* $ -* $- ; $ /= $ -+ $ *; _: $ ".= chr $ /+ $ *** $ -; $ /= $ / >> $ = || $ ** $ -; $ /= $ / &~ $ */ $ - and goto _; + print $ "," "

Pretty confusing! But let's run it through -MO=Deparse, and we get:

$= = '_' eq '_'; $- = () = ('(', ')'); $* = $- * $- * $-; $/ = $- + $*; _: $" .= chr $/ + $* ** $-; $/ = $/ >> $= || $* * $-; $/ = $/ & ~$* / $- and goto _; print $", "\n";

Still pretty confusing, but at least now I can parse it a little better.

$= = '_' eq '_';

$= normally defaults to 60 as the current page length of the selected output channel, but this just sets it to 1.

$- = () = ('(',')');

$- = () = qw; ( );; is like $- = () = ('(',')');

('(',')') is a two element list, and the =()= idiom Perl Idioms Explained - my $count = () = /.../g shows that $- receives the count of elements in the list, in other words 2.

$* = $- * $- * $-;

Equivalent to $* = 2 * 2 * 2, or 8.

$/ = $- + $*;

Sets $/ to 10.

_: $" .= chr $/ + $* ** $-;

_: is a line label, and I thought (as Errto noted above) it had to be at the begining of a line. $=, the list separator for list values interpolated into a double quoted string, defaults to a single space. The statement is equivalent to $" =  " " . chr 10 + 8 ** 2 , and ** binds tighter than + , therefore $" = " " . chr 10 + 64, or rather
$" = " J".

$/ = $/ >> $= || $* * $-;

This is: $/ = 10 >> 1 || $* * $-;

10 >> 1 will evaluate true (non-zero), so the right half doesn't gets evaluated, and $/ is subsequently set to 5.

$/ = $/ & ~$* / $- and goto _;

This can be written as $/ = 5 & ~ 8 / 2 , or a bit more clearly, $/ = 5 & ( ( ~ 8 ) / 2 ). This has the net effect of setting $/ to 1.

Going to the "_" line label, $= (currently " J") has chr 1 + 64, or "A" appended to it. then 1 >> 1 evaluates to 0, so this time the right hand of the expression is evaluated, and $/ is set to 8 * 2, or 16. Then $/ = $/ & ~ $* / $- can be restated as $/ = 16 & ( ( ~ 8 ) / 2 ), and sets $/ to 16.

Back to the "_" line label. $= (currently " JA") has chr 16 + 64, or "P" appended to it. 16 >> 1 is 8, so $/ is set to 8. and 8 & ( ( ~ 8 ) / 2 ) evaulates to 8.

Back to the "_" line label, $= (currently " JAP") has chr 8 + 64, or "H" appended to it. Then 8 >> 1 is 4, so $/ is set to 4. And what I think is the really clever "bit" ;) is that now 4 & ( ( ~ 8 ) / 2 ) evaluates to 0, so and goto  _; is skipped, proceeding to:

print $", "\n";

... which I think is pretty self-explanatory.

Whew! ++liverpole! That was a lot of fun!



--chargrill
$/ = q#(\w)# ; sub sig { print scalar reverse join ' ', @_ } + sig map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu +" );

In reply to Re: Token Abuse Japh by chargrill
in thread Token Abuse Japh by liverpole

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (8)
    As of 2015-07-30 10:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (271 votes), past polls