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
News of current disasters hidden in 1st Monasterians
No replies — Read more | Post response
by ambrus
on Dec 17, 2010 at 16:51

    This section has been unusually silent: no new obfuscated code for seventy-seven days. It is thus fitting that we contemplate together the words of the silent monk who demonstrated us the virtue of patience.

    use warnings; use strict; use Math::BigInt; our $scripture = q{ The First Letter of Erudil to the Monasterians
    1 Erudil, a hacker of Perl, To Vroom, the saints, and all the dwellers of the Monastery: 2 Mercy, peace and love be yours in abundance. 3 It is now a little more than two years since I joined this community of believers in Perl, and my appreciation of this place and its custodians and members continues to grow. 4 Brothers and sisters, I beseech you to continue fighting the good fight, showing patience and understanding to those who come to the gates of our blessed Monastery, bereft of clues and ignorant of our ways. 5 Do not rebuke them with harsh words such as "RTFM", but rather lead them gently - with URLs - so that they may learn wisdom. 6 Suffer the newbies to come unto us, instructing them of the many truths contained within the good book. 7 For who among us has never been in a state of error or ignorance? 8 Consider carefully the following: 9 Blessed are they that "use strict;", for their typos shall be caught before trouble arises. 10 Blessed are they that use "-w", for Perl itself shall show them the error of their ways. 11 Blessed are they that "use CGI;", for their parameters shall be passed without error. 12 Blessed are they that use CPAN, for exceedingly large shall be the number of wheels that they do not re-invent.
    13 Blessed are they that understand regexs, for they shall waste no time trying to parse HTML. 14 Blessed are you, when "they" insult you and ridicule you, and speak all manner of evil against you for using Perl, for great will be your reward when your project is finished in less time, and with less effort. 15 If there are those who refuse to accept our wonderful message, do not allow them to draw you into a fruitless flame war, and thereby bring disrepute upon yourselves and our Monastery. 16 Remember well: "What should it profit a man, if he should win a flame war, yet lose his cool?". 17 If this is an area of weakness for you, as it is for me, then I would encourage you, my fellow Monasterians, to consider a vow of silence as I have done, speaking rarely and with words carefully chosen to edify and inform. 18 Brothers and sisters, I commend you once again for restoring my faith in the idea of a viable, on-line community. And now, 19 May your syntax always be correct and your algorithms efficient. 20 May your references point to good data, and may you grow in the knowledge and understanding of our beloved language, Perl. 21 Amen and amen.
    }; my $r = Math::BigInt->bzero; for (split /^/, $scripture) { my($k, $n, $b, $v, $h, $p) = (-1, (0)x5); for (unpack "(A)*", $_) { if (ord) { if ($p) { $n++; eval { if ($p % 2) { $b *= $n / ++$k; } else { $v += $b; $b *= $n / ($n - $k); } } or $b = $p % 2; } $p = 0; } else { $p++; } } eval { $r *= $b * ($n - $k) / ($k + 1); $r += $v; }; } while ($r) { print+(" ", "a" .. "z")[($r->bdiv(23))[1]]; } print "\n"; __END__

    Update 2010-12-19: tried to fix motivational sentence at the beginning to be more meaningful. Not sure it worked.

Bitrotten obfuscations
3 direct replies — Read more / Contribute
by ambrus
on Oct 21, 2010 at 12:33

    Perl5porters wants us to believe that they care a lots about backwards compatibility. This is, however, not true, as shown by how many of my obfuscations doesn't work anymore with recent perl versions, or they give warnings even when you don't enable warnings.

    This node tries to be a comprehensive listing of which of my obfus still work and which don't. I'll try to update this node with newer breakage in the future.

    • LZ77 compression works (as of perl 5.16.1).
    • One-liner japh doesn't work: perl 5.10.0 breaks it with an unnecessary change that doesn't really fix a bug. It could be fixed somehow, for some of the similar obfus I link to still work.
    • Japh algebra works (as of 5.16.1).
    • Fun with duff's device and AUTOLOAD doesn't really count, because it was already sometimes broken when I wrote it, but it definitely doesn't work anywhere on perl 5.10.0 or later.
    • Charnames japh gives an unnecessary default warning on 5.12.0 or later. (It still gives the right result as of 5.16.1.)
    • Indigo japh doesn't work in perl 5.12.0 or later, because split in void context no longer fills @_. As a hotfix, prepend @_ = (that makes it work as of 5.16.1, though since perl 5.12 it also gives a default warning about pop _), but that ruins the aesthetics of the obfu. The second obfu in that same node works (as of 5.13.6).
    • Ode for getprotobyname still works, and so does the variant in Re (Obfu generator for): Ode for getprotobyname (as of 5.16.1).
    • Re: Pattern matching was already broken when I wrote it because it only worked on 32 bit perls – that's my fault, it wouldn't have been hard to make it work on 64 bit perls too.
    • Fast Japh works (as of 5.16.1).
    • Digisig doesn't work starting from 5.20, because the old feature it relied on got removed from perl.
    • Re: a poem still works (a of 5.16.1).
    • Ode for the CORE:: package works (as of 5.16.1), but starting from 5.12.0, it gives a default warnings that reveals something about the obfu. (It probably won't work starting from 5.20.0)
    • Faster japh works fine (as of 5.16.1).
    • Japh algebra revisited works (as of 5.16.1), but starting from 5.12.0 it gives an annoying default warning.
    • Twin-lines japh doesn't work and is completely unfixable: perl 5.13.6 fixes just the bug this uses. (It still works with at least 5.13.4.)
    • All of the ones in Re: Fibo Golf challenge on 3 monkeys still work as of ruby 1.9.2.
    • JAPH to commemorate the release of Perl 5.10.0 still works (as of 5.16.1).
    • All the ones in Short quines still work (as of 5.16.1), but variant e gives a default warning starting from 5.12.0. What's the deal with all these default warnings lately? Isn't the whole point of -w that the developer enables it to see what's wrong with the code but users of my code don't need to see it and worry about it?
    • A feature of use still works (as of 5.16.1).
    • General quine still works (as of 5.16.1).
    • Linux console japh still works (as of 5.16.1), provided you can find a linux console and stand far enough from your huge TFT that you can read the half feet high letters. In particular, while many Linux distributions set up the console as framebuffer text mode (which means the graphics card is set to graphical mode and the Linux kernel emulates a text console on it), but this obfu still works in such cases.
    • Re^2: The Oldest Plays the Piano still works (as of 5.16.1). The variants in Re^3: The Oldest Plays the Piano also work.
    • It's not my obfu, but only a slight change in Dollar Plus, so it's no surprise that Re: Dollar Plus still works (as of 5.16.1).
    • Both variants in Japh algebra, GF(128) edition still work (as of 5.16.1).
    • News of current disasters hidden in 1st Monasterians still works (as of 5.16.1).
    • \c*\c!\c0\c( still works (as of perl 5.16.1).
    • Just another unpack hacker still works (as of perl 5.16.1).

    This trend is also not specific to the obfu I write. The following section is of course just a selection, but you monks are encouraged to post tales about your broken code in replies: then maybe p5p will listen to us and stop these incompatible changes if they hear enough people complain. (Yes, I'm not completely serious, but this is the obfu section so I don't have to say that, right?))

Japh algebra, GF(128) edition
2 direct replies — Read more / Contribute
by ambrus
on Oct 02, 2010 at 17:13

    Did you know you could evaluate a polynomial over GF(128) in perl with pack and unpack and tr? Here's how.

    sub h { $_ = $_[0] = pack b208, 0 . unpack b362, $_[0]; tr/\0-\c?/\0/; tr/\0/\377/c; $_ } for (split //, "k6sNP2B}({ambrusLB%Ox)Z]n0*zf\0I3") { $y = $r; $v = join $r = '', a .. z; $r ^= h($r) & "\217" x 26 ^ h($v) & $y for 0 .. 6; $r ^= $_ x 26; } print $r;

    This code is based on the same idea as Dollar Plus, but written in a different style, so some of the credit goes to martin.

    Update: if you prefer one of these unreadable blocks of code, you can of course write this that way too (Update: reformatted blob from four lines to three.)

    sub h($){($_=$_[0]=pack b208,0 .unpack b362,$_[0])=~tr/\0-\c?/\0/;tr /\0/\377/c;$_}do{$y=$r;$v=join$r='',a..z;$r^=h$r&"\217"x26^h$v&$y for 0..6;$r^=$_ x26}for"k6sNP2B}({ambrusLB%Ox)Z]n0*zf\0I3"=~/./g;print$r

    Update: removed lots of spaces from end of lines of formatted code.

Dollar Plus
2 direct replies — Read more / Contribute
by martin
on Sep 30, 2010 at 09:36
    $;^=$;;$:='+';${::}{$:}=$_,for{},[];$==65;@+=map{$=<<=1; $=^=131,if+128&$=;chr$=}0..1<<8;@+{@+}=(0..126)x$=;print map{$:=$+[$+{$:}+$+{z}];$/=$;;$/=$;eq$/?$_:$+[$+{$/}+$+{ $:}]^$_,for@_;$/}@_=split//,'C|fqF[Ja-Dh{wzZf8t})1N@C:';

    My second contribution here does not like strictures, I admit, but mostly for aesthetical reasons. With a rather simple change it would. And ambrus is right: This kind is somewhat less like minigolf.

ASCII arithmetic
2 direct replies — Read more / Contribute
by martin
on Sep 29, 2010 at 06:16
    $%=2,$"=6;$;=ord"\c?";print+map{$%*="@_[4,4, ]";$=-=$=;$=*=$%%=$;,$=+=ord,$=%=$;for@_;chr $=}@_=split?,*?,q=|f475!%L(wz)Hmqkcz?ar~x<m=

    This one won't work correctly on an EBCDIC machine, I am afraid. But you can turn on strictures and warnings if you like.

JAPH palindrome.
5 direct replies — Read more / Contribute
by jffry
on Sep 24, 2010 at 16:55

    These scripts are the same forwards and backwards, excluding whitespace characters and newlines.

    Making a JAPH palindrome was fairly easy using comments.

    #!/usr/bin/perl #__ATAD__ print 'Just another Perl hacker,'#; #',rekcah lreP rehtona tsuJ' tnirp __DATA__# lrep/nib/rsu/!#

    It took me a bit of thinking to make one without the crutch of comment lines.

    #!/usr/bin/perl open fi, ">&STDOUT"; use constant X__ATAD__; print fi 'Just another Perl hacker,'; ',rekcah lreP rehtona tsuJ' if tnirp ;__DATA__ X tnatsnoc esu ;"TUODTS&>" ,if nepo lrep/nib/rsu/!#

    Now, trying to create a JAPH palindrome without the use of comments or DATA? :shudder:

    EDIT:Fixed based on blokhead's advice/corrections.

Chop chop chop
No replies — Read more | Post response
by Elliott
on Sep 07, 2010 at 06:21
    It's been years since I posted here but I had a sudden whim to try an obfu again. Here goes nothing (What DOES that mean?). Tested on Vista, Mac OS 9 and Linux.
    @a=split//,"Z~R_'QVj!^VL_.E]`OVj-]`O^AaZj>]LH]`OWx";map{$_=(ord$_)-oct + 36; unless($_>oct 11){$_-=3;$_="0$_"};$b.=$_}@a;$b=scalar reverse$b;while( +$b){ $y=chop$b;$y.=chop$b;$y.=chop$b;push@t,$y}map{print chr($_- hex hex d9 +)}@t
    The last time I posted was When JAPH retires (v 2.0) and it has to be said that was a more interesting project!
Keyboard Trouble
1 direct reply — Read more / Contribute
by Xiong
on Jul 03, 2010 at 02:34
    I splashed just a tiny bit of water into my kbd and now the 'one' key doesn't work. (This is not a joke{bang}) So, I've been avoiding the chars it used to produce.
    $l = 2/77; $| = 2; @F = ( '000*000*000*0*000*00*', '0*00*00*0*0*00*00*00*0*0*', '00*0*00*00*00*0000*00*', ); for (@F) { $. = 0; while ($g = length) { select $i, $j, $k, $l; $s = $_; $s =~ s/0/ /g; $m = unpack 'b*', pack 'v', $.; $m =~ s/0/ /g; $m =~ s/\d/*/g; print "\r", ' 'x$g, $s, $m, ' 'x2; $. += chop() ? 2/2 : $.; }; print "\n"; };
    - the lyf so short, the craft so long to lerne -
Great Idea!
No replies — Read more | Post response
by joecamel
on May 12, 2010 at 08:13
    ! ! ! ! ! ! ! i ;$_=join( q!!=>map{$!=$!& 0;map{s$![^\]! =s!! \$x-Y\\[@!]!Y=$! =$x ;$!+=s$[q!=>\$x-Y= [@! ]$!={$g}@$_;$g=i&& q!! . chr ($! +0x3E)}([\\$!=>{!! !$! =>! chr , [!$!]}]=>[\$!=>\$!=>\$! =>[!$!]]=>[\$!=>\$!=> {$!=>[$!]}=>{!$!=>[ $!]}]=>[\\$!=>{$! =>[Y]}]=>[\$!=> {$!=>[!$!]}=> \\!$!]=>[ \\$!])) ; print=> ! ! print=> ! ! print=> ! print=> print=> print
turn it upside-down
4 direct replies — Read more / Contribute
by AutomateWithPerl
on Apr 20, 2010 at 13:21
    s/\:\(/\:\)/g;

Set the new obfuscation standard
Title:
code@?#!:
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.