Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

JAPH - My first try

by ruoso (Curate)
on Sep 22, 2005 at 17:28 UTC ( [id://494217]=obfuscated: print w/replies, xml ) Need Help??

This is my first obfuscation...

print&{sub{my$z=$_[0];for(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$c=$_;my$l=$i++; @$::[$l]=sub{substr(${$_[0]},$l-24,1)=chr(ord(substr( ${$_[0]},$l-24,1))-$c)if($l>23);substr(${$_[0]},$l,1)= ' 'if($c&&$l<24)};&{@$::[$l]}(\$z);};$z}}(q#root#x6)."\n";

Comments welcome...

daniel

Replies are listed 'Best First'.
Re: JAPH - My first try
by liverpole (Monsignor) on Sep 23, 2005 at 00:06 UTC
    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).$/

      Great catch! ++

      1. You can get rid of all 'my'
      2. You don't need $c = $_, either
      3. You don't need an array $::$l, just use a scalar $::

      Actually, this was because I was calling the subs outside the for on the earlier tries. To use the closures as closures, the 'my's and the $c = $_ are necessary, but in this code there isn't properly a closure. I'll try to play a little more with closures and some ideas I'm brainstorming to a second try...

      daniel
            and some ideas I'm brainstorming to a second try...

        Excellent -- I look forward to seeing your next one!  Keep up the good work!

Re: JAPH - My first try
by cristian (Hermit) on Sep 22, 2005 at 20:46 UTC
    I like , good obfu
    &{ sub { print @_; } } ("hello"," ","world!")
Re: JAPH - My first try
by Hue-Bond (Priest) on Sep 22, 2005 at 19:47 UTC

    Nice. That $:: gave me an interesting time ;^). Where can I read about it? Grepping perlmod for "::[^a-z]" didn't show me much.

    --
    David Serrano

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found