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

Undocumented Operator Japh

by liverpole (Monsignor)
on Nov 21, 2006 at 17:17 UTC ( #585310=obfuscated: print w/ replies, xml ) Need Help??

When writing Perl code, it's always fun to use some of the undocumented operators.

The good ol' +- operator always comes in handy.  My personal favorite is the ever-reliable '= operator.  And what obfuscation would be complete without a terminal /+ operator?

Can you find any other undocumented operators below?

@ == "GqwpWrlplbnTbnpDwghav"=~ /.../g; @ +- map { +map++ $_,@ =} +$ = ... 3**7; @ '= split /(?=[A-Q])/, join $* ,@ =; die + qq + @'$ /+

The inspiration for the technique used came indirectly from this node by blazar.

Update:  Fixed wording, as pointed out by jdporter.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Comment on Undocumented Operator Japh
Select or Download Code
Re: Undocumented Operator Japh
by wulvrine (Friar) on Nov 21, 2006 at 18:24 UTC
    Stop breaking deparse! You are making my head hurt! <secret ++>
    My eyes are spinning from working this one out, even with help!
    Heck of a pickup on an obscure ahem feature :) GREAT JOB!

    s&&VALKYRIE &&& print $_^q|!4 =+;' *|
Re: Undocumented Operator Japh
by chargrill (Parson) on Nov 21, 2006 at 22:52 UTC

    Clever! liverpole++

    Here's a crack at deobfuscating it:

    First things first, fix that pesky whitespace.

    @= = "GqwpWrlplbnTbnpDwghav" =~ /.../g; @+ - map { +map ++$_, @= } + $= ... 3**7; @' = split /(?=[A-Q])/, join $*, @=; die +qq+ @'$/+

    Clean up a few things, simplifying where possible:

    @= = "GqwpWrlplbnTbnpDwghav" =~ /.../g; @+ - map { map ++$_, @= } + 60 ... 2187; @' = split /(?=[A-Q])/, join $*, @=; die qq" @'$/"

    But there's still those extra "+"'s and "-"'s in that second line... Well, thanks to that hint about blazar's post, I think I know what's going on, so let me try something...

    for( qw( Gqw pWr lpl bnT bnp Dwg hav ) ){ my $num = $_; #for( 60 ... 2187 ){ $num = ++$num } # the above changed to the below to "deobfuscate" the deobfuscation. for( 60 .. 2187 ){ $num++; } push( @array, $num ); } print "$_\n" for @array; OUTPUT: Jus tAn oth erP erl Hac ker

    Success!

    So here's what's going on: line 1 sets the @= array to some values, which happen to be the equivalent of "( 'Gqw', 'pWr', 'lpl', 'bnT', 'bnp', 'Dwg', 'hav' )".

    Line 2 cleverly "re-maps" (using a map inside a map, nonetheless) the @= array by ++ "incrementing" every value 2,127 times - the exact number of times required to "increment" Gqw to Jus*. The preceeding @+ - just adds a little line noise, as it doesn't seem to affect the final result if removed. Same with the + in front of $= (which, incidentally, (as documented ;) defaults to 60).

    Line 3 joins @= by the value of $*, which is (as documented ;) undefined, giving us "JustAnotherPerlHacker", which is then split in between a lowercase character and a following uppercase character thanks to the zero width positive look-ahead assertion /(?=[A-Q])/, and the resulting list from the split is stored in @'.

    Finally, with a few + cluttering things up (and used as qq's quoting character for interpolating the values of the variables in the string given to die), you 'print' the contents of @', trusting that (as documented ;) the default value of a single space for $" hasn't changed, and $/ also defaults (as documented ;) to a newline.

    * (The bit of perldoc perlop that details this is: The auto-increment operator has a little extra builtin magic to it. ... If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern "/^[a-zA-Z]*[0-9]*\z/", the increment is done as a string, preserving each character within its range, with carry .... Incrementing "Gqw", and you get "Gqx")

    Update: Cleared up the "obfuscated deobfuscation" as noted by ysth, though the original test was written to most closely resemble (from at least my point of view) the original obfuscated code. Apologies for any confusion. Also added a little extra explanation (with reference to associated documentation).



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
      for( 60 ... 2187 ){ $num = ++$num }
      Please don't obfuscate your deobfuscation.
      Nicely done, chargrill, as always++

      One of the fun parts of creating the obfuscation was writing the subroutine to "decrement" a word (eg. "Jus"-- => "Jur").

      It wasn't clear initially clear how many "increments" I was going to want to make, and if it turned out to be more than a few (as it certainly did), I needed to a subroutine to do it.

      This was what I ended up with:

      sub decrement_word { my ($pword) = @_; my @vals = map { ord $_ } (split //, $$pword); my $idx = $#vals; while (1) { if ($vals[$idx] != ord('a') and $vals[$idx] != ord('A')) { --$vals[$idx]; last; } if (0 == $idx) { shift @vals; last; } $vals[$idx] += 25; --$idx; } my $word = join '', map { chr } @vals; $$pword = $word; }

      It's too bad, I think, that a word "decrement" isn't part of the Perl language, at least for the obfuscatory potential it would provide. ;-)


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Undocumented Operator Japh
by diotalevi (Canon) on Nov 22, 2006 at 00:29 UTC

    I dub this, "most readable JAPH evar!" It's pretty though. I like it.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://585310]
Approved by kwaping
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-08-20 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (111 votes), past polls