Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Well, as you can see, I put more effort into implementing the algorithm than obscuring it. I mean, I say Huffman in the title already. Sheesh...

Anyway, jynx was kind enogh to msg me with some much needed hints. Well, a conversation started on our scratchpads. With jynx's permission I'll now repost it, with each turn in a new reply. But we'll start with jynx's initial response.

Not to harp, but here's a few comments1:
  • Overuse of parentheses breaks up the code into bite-size chunks for others, making it easier for them to "chew"
  • Explicit checks against numbers clue in the reader to an important value
  • Explicit minor changes to variables make sure that everyone knows where you're coming from (e.g. $i++)
  • Extraneous white space further breaks things so the reader can stop and think about a chunk
  • Explicit assignment to variables gives the reader too much notice as to where things come from
  • Blocks of code make obvious chunks that can be parsed seperately to slowly form a larger picture
  • Clearly one can't remove all instances of the above from an obfu (or at least, not always), but reducing instances should help obfuscate the code...
Making some changes along those lines yields:
#!/usr/bin/perl @t=("12","34","56","7 ","89",":h","er",";k","<t","=a","lc","ju","sn"," +op"); @m=split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0"; do{ $n=$i++%8?$n:ord shift@m; $x=ord substr$t[$p],($n&128)>>7,1; $p=($x&240)==48?$x&15:0; !$p&&print chr$x; $n<<=1; }until($i==91);
Notice also i took out the 'use integer' statement and the initialization of variables since they're unnecessary. Since Perl will complain about uninitialized values i also took off the -w. For testing purposes it's useful to keep such things in, but removing unnecessary things also removes extra clues for the reader :-)

Next we can take out variables that are only used once and remove instances where conditions overlap. In particular to this obfu, if $p is zero, we print. But on the previous line we just set it to zero. We can combine the two statements and use print's return value effectively here. The following is an iterative process of combining overlapping statements and reducing variables:

# 1 # collapse printing into the $p assignment @t=("12","34","56","7 ","89",":h","er",";k","<t","=a","lc","ju","sn"," +op"); @m=split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0"; do{ $n=$i++%8?$n:ord shift@m; $x=ord substr$t[$p],($n&128)>>7,1; $p=($x&240)==48?$x&15:-1+print chr$x; $n<<=1; }until($i==91); # 2 # Collapse the $x assignment into the $p assignment @t=("12","34","56","7 ","89",":h","er",";k","<t","=a","lc","ju","sn"," +op"); @m=split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0"; do{ $n=$i++%8?$n:ord shift@m; $p=(($x=ord substr$t[$p],($n&128)>>7,1)&240)==48?$x&15:-1+print chr$ +x; $n<<=1; }until($i==91); #3 # Collapse the $n assignment into the $x assignment @t=("12","34","56","7 ","89",":h","er",";k","<t","=a","lc","ju","sn"," +op"); @m=split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0"; do{ $p=(($x=ord substr$t[$p],(($n=$i++%8?$n:ord shift@m) &128)>>7,1)&240)==48?$x&15:-1+print chr$x;$n<<=1; }until($i==91); #4 # Remove @t and replace it with a constant list @m=split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0"; do{ $p=(($x=ord substr("12","34","56","7 ","89",":h","er",";k","<t","=a" +,"lc","ju","sn","op") [$p],(($n=$i++%8?$n:ord shift@m) &128)>>7,1)&240)==48?$x&15:-1+print chr$x;$n<<=1; }until($i==91); #5 # condense the previous @t, removing quotes to save space @m=split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0"; do{ $p=(($x=ord substr+(split/,/,'12,34,56,7 ,89,:h,er,;k,<t,=a,lc,ju,sn +,op') [$p],(($n=$i++%8?$n:ord shift@m)&128)>>7,1)&240)==48? $x&15:-1+print chr$x;$n<<=1; }until($i==91); #6 # Remove @m, replacing it with a constant list # This requires a smaller variable for the 'shift' effect... do{ $p=(($x=ord substr+(split/,/,'12,34,56,7 ,89,:h,er,;k,<t,=a,lc,ju,sn +,op') [$p],(($n=$i++%8?$n:ord ((split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0")[$.++ +]) )&128)>>7,1)&240)==48?$x&15:-1+print chr$x;$n<<=1; }until($i==91); #7 # Change all the variables to 'strict compliant' ones... # Remove extra semi-colons and parentheses... do{$a=(($_=ord substr+(split/,/,'12,34,56,7 ,89,:h,er,;k,<t,=a,lc,ju,s +n,op')[ $a],(($b=$;++%8?$b:ord ((split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x06\xbc\x8e\xe0")[$.++]) +) &128)>>7,1)&240)==48?$_&15:-1+print chr;$b<<=1}until$;==91 #8 (final version) # Split up the previous @m for allignment issues do{$a=(($_=ord substr+(split/,/,'12,34,56,7 ,89,:h,er,;k,<t,=a,lc,ju,s +n,op')[ $a],(($b=$;++%8?$b:ord((split/ */,"\x00\x50\xA5\xd2\xc5\xbb\x96\xef\x0 +6\xbc". "\x8e\xe0")[$.++]))&128)>>7,1)&240)==48?$_&15:-1+print chr;$b<<=1}unti +l$;==91
It's now just a block of code with little whitespace that readers must attempt to swallow all at once. It still uses too many parentheses unfortunately, but Perl would have problems parsing correctly without them.

Anyway, that's the process i went through after running your japh. While i'm not the best at obfu, hopefully this will help a little...

nuf evah,

1NOTE: i usually format to 60 places for monastery reasons, but sometimes, particularly in cases of obfus, i format to 80 characters, which is standard terminal width. Because of this i must appologize for the random red +'s everywhere (i've set my page preferences to wider than 60 chars to accomodate this 80 char fetish :)

In reply to Re: Huffman once again by fsn
in thread Huffman once again by fsn

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, 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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2019-07-24 02:13 GMT
    Find Nodes?
      Voting Booth?
      If you were the first to set foot on the Moon, what would be your epigram?

      Results (32 votes). Check out past polls.