Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
The stupid question is the question not asked

Obfuscated code

( #1597=superdoc: print w/ replies, xml ) Need Help??

Got some code which would take a Perl grand master to understand without running it? Post it in this section so we can stare at it in awe.

Word of warning, though: Don't be too cocky with your post — almost inevitably someone will post a reply that does the exact same thing in even fewer characters!

New Less than Readable Code
Dilbert don't warn!
4 direct replies — Read more / Contribute
by tobyink
on Jul 08, 2013 at 05:38

    This is an interesting feature of Perl that's recently come up on p5p as a candidate for removal. Not obfuscated, but obscure certainly.

    #!/usr/bin/env perl use warnings; "pointy haired boss"; "dilbert"; "dogbert"; "wally";


    Useless use of a constant ("pointy haired boss") in void context at sc line 5. Useless use of a constant ("dogbert") in void context at li +ne 7. Useless use of a constant ("wally") in void context at line + 8.

    What? Why doesn't "dilbert" generate a warning?

    Turns out that before pod became the standard for Perl documentation, people used to embed strings of nroff in Perl scripts. Any strings that begin with "di", "ds" or "ig" look enough like bits of nroff to be exempt from the void warning.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
A bit of fun with pack/unpack
2 direct replies — Read more / Contribute
by FloydATC
on Jun 28, 2013 at 04:28

    My first, humble attempt at writing (intentionally) obfuscated code:

    use strict; use warnings; @==map{unpack('B24',pack('V',$_))}(12580855,16776063,103792,10764419,8 +561235,856483,1974885); foreach$"($[..23){$:=$[;foreach$\($[..6){$:.=substr($=[$\],$",!$[)}pri +nt(pack('B8',$:))}print$/;
    -- FloydATC

    Time flies when you don't know what you're doing

Lightly toasted JAPH
No replies — Read more | Post response
by rjt
on Jun 27, 2013 at 07:59

    This JAPH will hopefully give you brief pause, in a meditative sort of way. Stop and smell the roses. --<--<@

    If you like cracking ciphers, take a look at the spoiler tag below first, before you take a hard look at the JAPH code.

    sub _{q{%-2L9^!F.Q&4B5B+/7C*3C6 1B' (C,08 # $) "}}sub O{chr$.}$. =($|||=!$!^$.)^33,;print@@if map{$%=-33+ord substr&_,$_;$->$%?$. ++:$%<1<<2<<3?$@[$%]=O:($.+=$%-31)}0..length _


Glob in the JAPH
1 direct reply — Read more / Contribute
by Eily
on Jun 17, 2013 at 19:00

    This morning, the weather was quite warm and sunny, so I decided to take my bike to go to work. I didn't bother looking what it would be like in the evening. So I ended up in front of my computer, waiting for the rain to stop falling long enough for me to come back home, because I hadn't thought about taking a jacket. To pass the time, I made this:

    ($R,$B)=(q, another,,q( Perl hacker,),$a=Just);$, =$V;m;(.)\(\)?;;*V=$::{$1};$\=$V;BEGIN{$|;$_=\$:: {b};m;(.)\(\)?;;*V=$::{$1}}print @$_ for [$a,$b],

    My favorite JAPHs are those where the printed text isn't already obvious in the code. So I could have added some encryption or something to this one, but I thought I should rather stick to one main concept (concept I stumbled upon by accident) and shape (quite literally) this script around it. I still used some other obfuscations here and there to prevent the whole script from being too obvious, and to make it fit in a rectangle.

    It does not run under strict, and warnings may make it easier to understand.

1 direct reply — Read more / Contribute
by varnie
on Jun 17, 2013 at 12:23
    Hi there. Here's my JAPH:
    #!/usr/bin/perl use warnings; use strict; my$k='my$i=0; foreach my $v (-4,26,10,-4, -104,-56, -61 ,-79,-94,-127 ,-152,-162, - 268,-245,-250 ,-264,-298, - 403,-361,-399 ,-429,-454, - 494,-516){$_[ $i++]+= $v; } join"",map{chr }@_;';foreach( reverse(12..35) ){$k="sub{$k}-> (\@_, int map{( int)x\$_}(1..$_ ))"}print eval$k
    Shrinked version:
    #!/usr/bin/perl use strict; use warnings; my$k='my$i=0;foreach my$v(-4,26,10,-4,-104,-56,-61,-79,-94,-127,-152,- +162,-268, -245,-250,-264,-298,-403,-361,-399,-429,-454,-494,-516){$_[$i++]+=$v}j +oin"",map {chr}@_;';foreach (reverse (12..35)){$k="sub{$k}->(\@_,int map{(int)x\ +$_}(1..$_ ))"}print eval $k;
Pumping JAPH
1 direct reply — Read more / Contribute
by choroba
on May 13, 2013 at 11:03
    My first JAPH. Works under strict and warnings, too.
    $|--;for($/=1/10;$/<=1/2;$/+=50e-7){$\=qq/J,\r/; substr$\,$/*length$\,$/-$/,$_,for split/(.{2})/, q/ursetk caanho tlhreerP /;print'';}warn qq/\n/;

    Update: Retitled.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Length of array in hash of arrays
1 direct reply — Read more / Contribute
by ambrus
on May 09, 2013 at 09:57


    I have a hash of arrays like this:

    my %g = ( k => [8, 2, 10, 2, 1, 3], l => [10, 7, 9, 0, 1] );
    I know I can access the first element in one of the arrays like $g{k}[0]. But how do I get the length of that array?


    Just try using random sigils, some combination is bound to work. The following script eases this task: it quickly runs all combinations of random sigils and prints the code that gives the right answer.

    use 5.014; no warnings; # some non-sensical combination of sigils would give warn +ings use strict; # we want answers without symbolic references my %g = ( k => [8, 2, 10, 2, 1, 3], l => [10, 7, 9, 0, 1] ); sub sigil_combination { sprintf("%X", $_[0]) =~ y/0-9A-F/$@#%*~^\->(){}.,;/r; } for my $n0 (1..1e5) { my $c = "length " . sigil_combination($n0) . "g{k}"; if (6 == eval $c) { say "$c"; } } __END__
Fibonacci Sequence
2 direct replies — Read more / Contribute
by skunix
on Feb 27, 2013 at 00:59
    $~=$^=1;s//1 1 /;_:$~^=$^ ^=$~^=$^;$_.=($~=$~+$^." ");($~<99)?goto _:print
Closure JAPH
No replies — Read more | Post response
by aitap
on Feb 06, 2013 at 13:46
    Just thought that a sub returning itself would be a funny thing to write. Well, here it is, a dragon eating its own tail, even if it's not looking like the original one:
    #!/usr/bin/perl use warnings; use strict; my ($j,$ a,$p,$h);$ j=sub{print( chr($p+=$a->[$ h++]));$j};;;$a =[0, split "[: \n]+", q/43 -002:1 -084 065:13 0001 000005 -0012 -00003 000013 -82 00048 21:13:-6.00:-76:72 -007.:02:00008.00 :::-6.00:::013 -70:3::-70:.64 /];$p=0x4a ;;$h=0; $j->()->()->()->()->()->()->()->()->()->()->()->()->()->()->()->()->() +->()->()->()->()->()->()->()->();
PERL hackers bank! can you get into the safe
1 direct reply — Read more / Contribute
by perlaintdead
on Jan 10, 2013 at 00:04

    any NSFWshow fans in obfu? also bonus points if you can crack the hash

    #!/usr/bin/perl print "Welcome to the Internation PERL Hackers Bank\n"; print "Pin: ";my$Pin =<> ;my$fapper;chomp $Pin;$Brian=crypt$Pin, "";goto l;i:if($Brian eq$fapper xor-!1){ print "successfull. you leet!";}else{print "you no leet yet."}; exit;f:w:n:n:n:nin:nnhz:ng:gh:l:Ls:b:w:; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!000;!!!!!!!!!!!!!!!!!!!!!!! +!!!!!1; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!!1; my@c;my@e=( "E","g","k","n","K", "s","w","R","a","B", "v","S","a","C","g", "a","O","g","s","a", "8","f","A","s","A"); local@a;push(@a,sort ord 80 );unshift(@a, sort'c');sort@a;my$r =!!defined$Pin ;1xor 1or 0;my$D=(not(not( not(not(not(not(not( not($#a)))))))));for (++$D;delete$e[($r)] ;$#e==$e[$r]){$~;$ r =$ r+$ D;::;}map{11; 1;$fapper=join undef, ${_},$fapper;()*8}@e; goto i;I:I:I:I:I:I:I:

Set the new obfuscation standard
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 musing on the Monastery: (13)
    As of 2014-04-23 18:17 GMT
    Find Nodes?
      Voting Booth?

      April first is:

      Results (552 votes), past polls