It's very inspired, ruoso!  I like your use of closures, but especially turning one string into another ... muito boa ideia!

I'll return your favor, providing a spoiler to your obfuscation, as well as a suggestion for making it 3 lines instead of 6:

#!/usr/bin/perl + # Converts 'rootrootrootrootrootroot' into 'just another perl hacker' # Data contains 48 bytes: first 24-bytes => (0=skip, 1=convert to spa +ce) # and last 24-bytes are ascii offsets for character conversions, and i +s # iterated twice through. my @data = qw( 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 + 0 0 8 -6 -4 0 0 14 1 5 -2 7 10 2 0 -1 10 2 6 0 7 19 15 4 +10 2 ); + my $p_turn_root_into_japh = sub{ my $arg = shift; for (my $i = 0; $i < @data; $i++) { my $c = $data[$i]; my $pclosure = sub { my $p = $_[0]; # Uncomment next line to see string conversion progression # printf "[$arg]\n"; if ($i > 23) { # Now convert 1 char at a time from 'rootrootroot...' # to the target char, by subtracting appropriate ascii + val. # Comment out next line only, and you get: # "root ootroot ootr otroot" substr($$p, $i-24, 1) = chr(ord(substr($$p,$i-24,1))-$ +c); } if ($c && $i < 24) { # Comment out next line only, and the end result is: # "justranotherrperlohacker" substr($$p,$i,1) = ' '; } }; $pclosure->(\$arg); } return $arg; }; + printf "%s\n", $p_turn_root_into_japh->('rootrootrootrootrootroot');

Here's some suggestions on how to shorten it:

  1. You can get rid of all 'my'
  2. You don't need $c = $_, either
  3. You don't need $l=$i++, just use $l, and post-increment at the end
  4. You don't need an array $::[$l], just use a scalar $::
  5. You don't need &{$::}, just $:: is enough
  6. Use the ternary operator to avoid one 'substr'
  7. You're using a lot of bytes (24) just to represent 24 bits -- convert them to 0x21010.
  8. Change "\n" into $/ to save space
  9. Finally, get rid of extra ';' and parentheses everywhere
Now you have 3 lines instead of 6!
print&{sub{$z=$_[0];for((0)x24,qw#8 -6 -4 0 0 14 1 5 -2 7 10 2 0 -1 10 + 2 6 0 7 19 15 4 10 2#){$::=sub{substr(${$_[0]},($l>23)?$l-24:$l,1)=chr(($l<24& +&0x21010& 1<<$l)?32:ord(substr ${$_[0]},$l-24,1)-$_)};&$::(\$z);$l++};$z}}(q#roo +t#x6).$/


In reply to Re: JAPH - My first try by liverpole
in thread JAPH - My first try by ruoso

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.