Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

A Simple JAPH

by Athanasius (Archbishop)
on May 07, 2012 at 16:02 UTC ( [id://969289]=obfuscated: print w/replies, xml ) Need Help??

My first effort:

$_='penflillggplmhlllpkolhmhgiokmpmhkegopckdlmlckemhge'; tr/g-p/0-9/;my@x=map{-84+hex$_}$_=~/[A-F0-9]{2}/gi;my@y= shift@x;push@y,$_+$y[-1]for@x;print join'',map{chr$_}@y;
“...an ill-favoured thing, sir, but mine own.” —As You Like It (Act 5, Scene 4)

Regards,

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re: A Simple JAPH
by ambrus (Abbot) on May 07, 2012 at 21:09 UTC

    This obfu is nice because it's hard to see at first what it will print. Allow me a few minor comments though. (I'll use spoiler tags to not spoil anything for readers who hasn't decoded the obfu yet.)

    Firstly, it seems strange to me to see three apparently unnecessary mentions of $_ in a code like this: one after hex, one after chr, and you can remove the $_=~ part from the match too. Is there any reason you have these in the text?

    Secondly, is there a good reason to spell out the valid characters in the regex as /[A-F0-9]{2}/gi instead of just /../g or /\w\w/g? I could understand using a range like [A-F0-9] if you had extra invalid letters (from [s-z]) in the string that do nothing, but your string has no such letters. Writing [A-F0-9] gives an explicit clue to the reader that you are expecting hexadecimal digits. Is that what you want?

    Thirdly, the join'', part also seems unnecessary: print will concatenate the characters anyway.

    Lastly, I prefer if an obfu like this prints a newline after the message. This is not an absolute requirement, but if the obfu is easy to change to do this, then it's better that way. In this case, I think you'd just have to change the end of the long string from "mhge" to "mhgeji". If you think that would make the first line too long, just break the string to two lines. You can do this either by using two string literals like

    $_='first part'. 'second part'
    or by leaving whitespace in the string that your regex will skip, such as
    $_='first part second part'

    For example, after the changes I suggested above, plus some rearrangement to get the right edge of the text to line up again, I get this.

    $_='nflillggplmhlllpkolhmhgiokmpmhkegopckdlmlcke mhgejipe';tr/g-p/0-9/;my@x=map-84+hex,/\w./gi;my @y=pop@x;push@y,$_+$y[-1]for@x;print map{chr}@y;

    Let me list some specific good points of this obfu too.

    You're not using unpack"C*",pack"H*",$_ to decode the string of hexadecimals. That would be both longer than the map{hex}/\w./g you're using and easily recognizable for seasoned obfuscation readers.

    Secondly, you put the -84 constant together with the hex instead of in the $_+$y[-1], thus making its meaning more difficult to see. As your code is now, I first see the -84 term, and don't understand what it's doing until later when I see that the numbers are used as differences which is why you want negative numbers.

    Thirdly, you wrote the code as separate statements each doing one step of the computation. This seems actually seems to suit this obfu more than a traditional terse style where you'd write everything in one statement, such as

    y/g-z/0-9/,print chr($_y+=-84+hex)for"penflillggpl mhlllpkolhmhgiokmpmhkegopckdlmlckemhgeji"=~/\w./g;
    as the separate statements put the related operations far away from each other, thus making the code less readable, but still short enough.

    (Ps. Modifying the above to use the y///r switch thus making the statement even more readable is homework for reader.)

      Wow! Thank-you ambrus for such detailed feedback.

      Taking (most of) your comments on board, the JAPH now looks like this:

      $_='penflillggplmhlllpkolhmhgiokmpmhkegopckdlmlck' .'emhgeji';y,g-p,0-9,;my@x=map{-84+hex}m;\w.;g;my@ y=shift@x;push@y,$_+$y[-1]for@x;print(map{chr}@y);

      I should have mentioned an additional requirement I imposed on myself: the code runs clean under use strict;and use warnings;

      This is fun!

      Regards,

      Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://969289]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found