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
Length obfuscation
3 direct replies — Read more / Contribute
by trizen
on Aug 03, 2011 at 08:51
    Hi monks, this is my first post.
    # Global mode (pretty slow on large files) $_=q qrea ncJertsa ,thelhPkour q,my $i=length; while($i){s/(.{$i})(.)/$2$1/g;--$i}print+$_.$/
    # Non-global $_=q qnPteorJlt hhascekaerru, q,my $i=length; while($i){s/(.{$i})(.)/$2$1/;--$i}print+$_.$/;
    # Opposite code: $_=q qJust another Perl hacker,q;until($i eq length){s/(.)(.{$i})/$2$1/g;++$i}print+$_.$/
    It's very simple and easy to understand. Note: for files should be added '/s'
(almost) foldl
7 direct replies — Read more / Contribute
by dk
on Jun 07, 2011 at 17:16
    There runs now a topic on moscow.pm list on how to calculate a sum of numbers in a list, basically this:
    my $sum = 0; $sum += $_ for @list;
    but without using extra vars and modules (nurture your inner purist, yes :) Now I believe I found a line that wasn't discovered before:

    print sub { (map {splice @_, 0, 2, $_[0] + ($_[1] // 0)} @_)[-1] }-> ( +1,2,3,4,5);

    Hopefully you'll find it amusing :)

Pulling JAPH out of the iterated SHA512 of the code...
1 direct reply — Read more / Contribute
by Grimy
on Jun 07, 2011 at 10:12
    Greetings!

    I realized that my previous JAPH was thoroughly unattractive because you had to squint in order to decipher it, which isn't pleasant. That's why I came up with this one. It is based on the same idea of extracting JAPH one character at a time from successive iterations of the SHA512 of the code, but now features whitespaces(!) and pretty symmetrical subroutines. I hope you have as much fun understanding it as I had writing it. Here it is:

    use strict; use Digest::SHA substr(q/=sha512(\/), $/, q); %_ = (undef($/) && (open *q, $0) => undef($/) || ($/=<q>) !~ s+= \w\+=+= =+??? : 6); $/ =~ s+[\xD\xA]\++\xA+g; $_ = aJcpbneUbBdThmaWbMqehybAhIkAaPeYavrNcjd0bvb9gxfjay=>; y #a-zA-Z0-9_$/y #\0->y;#; y #a-zA-Z0-9_$/y #\0->y;#; print substr($/=sha512($/), $_, 1) for (map &_ => /./gs); sub _ ( ) { # } ( ) _ dus sub x ($) { ! q ! } ($) x dus { 0 x (0) rox ! xor (0) x 0 } !((//m...//m) ^ (m\\...m\\))? (64)x + (ord) : (ord) + x(49) } # {

    perl -w it, it runs without warnings and prints exactly "Just another Perl hacker,".

    Good start points to understand what happens:

    EDIT: Here's an alternative version of the code that doesn't read it's own source, making it more portable (possible use as a one-liner, no trailing whitespace problem) but much less interesting:

Pulling JAPH out of nowhere...
1 direct reply — Read more / Contribute
by kejohm
on Jun 04, 2011 at 09:13

    Hi monks,

    This is my first JAPH. Inspired by perlpacktut.

    print pack('C',unpack('%c*',unpack('W',pack('J')))+unpack('%c*',unpack +('a',pack( 'A')))-unpack('%B*',unpack('U',pack('A')))+unpack('%b*',unpack('a',pac +k('A')))), pack('C',unpack('%Z*',unpack('W',pack('A')))+unpack('%W*',unpack('n',p +ack('V'))) -unpack('%C*',unpack('a',pack('A')))),pack('C',unpack('%a*',unpack('C' +,pack('A') ))+unpack('%U*',unpack('b',pack('C')))-unpack('%C*',unpack('a',pack('A +')))- unpack('%B*',unpack('B',pack('L')))),pack('C',unpack('%U*',unpack('c', +pack('A')) )+unpack('%U*',unpack('b',pack('Z')))-unpack('%Z*',unpack('a',pack('A' +)))-unpack ('%b*',unpack('Z',pack('A')))),pack('C',unpack('%U*',unpack('a',pack(' +A')))), pack('C',unpack('%a*',unpack('H',pack('A')))+unpack('%a*',unpack('J',p +ack('j'))) -unpack('%b*',unpack('a',pack('A')))),pack('C',unpack('%C*',unpack('U' +,pack('A') ))+unpack('%B*',unpack('W',pack('A')))+unpack('%b*',unpack('H',pack('h +')))),pack ('C',unpack('%W*',unpack('c',pack('A')))+unpack('%b*',unpack('W',pack( +'A')))+ unpack('%B*',unpack('H',pack('A')))),pack('C',unpack('%U*',unpack('C', +pack('A')) )+unpack('%C*',unpack('I',pack('J')))-unpack('%c*',unpack('Z',pack('A' +)))-unpack ('%b*',unpack('a',pack('A')))),pack('C',unpack('%C*',unpack('C',pack(' +A')))+ unpack('%b*',unpack('H',pack('A')))),pack('C',unpack('%Z*',unpack('C', +pack('A')) )),pack('C',unpack('%C*',unpack('W',pack('A')))+unpack('%b*',unpack('W +',pack('A' )))+unpack('%b*',unpack('H',pack('A')))+unpack('%b*',unpack('J',pack(' +J')))+ unpack('%b*',unpack('Z',pack('A')))),pack('C',unpack('%C*',unpack('Z', +pack('A')) )),pack('C',unpack('%W*',unpack('b',pack('S')))+unpack('%Z*',unpack('Z +',pack('A' )))),pack('C',unpack('%C*',unpack('U',pack('A')))),pack('C',unpack('%W +*',unpack( 'c',pack('A')))+unpack('%B*',unpack('c',pack('A')))+unpack('%b*',unpac +k('H',pack ('A')))+unpack('%B*',unpack('b',pack('A')))+unpack('%b*',unpack('Z',pa +ck('A')))) ,pack('C',unpack('%c*',unpack('c',pack('A')))+unpack('%b*',unpack('c', +pack('A')) )),pack('C',unpack('%C*',unpack('a',pack('A')))),pack('C',unpack('%U*' +,unpack( 'C',pack('A')))+unpack('%B*',unpack('H',pack('A')))),pack('C',unpack(' +%Z*', unpack('H',pack('A')))+unpack('%Z*',unpack('i',pack('N')))-unpack('%b* +',unpack( 'Z',pack('A')))),pack('C',unpack('%C*',unpack('H',pack('A')))+unpack(' +%c*', unpack('C',pack('v')))+unpack('%b*',unpack('Z',pack('A')))),pack('C',u +npack( '%W*',unpack('c',pack('A')))+unpack('%b*',unpack('c',pack('A')))-unpac +k('%B*', unpack('a',pack('A')))),pack('C',unpack('%A*',unpack('C',pack('A')))), +pack('C', unpack('%c*',unpack('C',pack('A')))+unpack('%U*',unpack('c',pack('N')) +)-unpack( '%A*',unpack('Z',pack('A')))-unpack('%b*',unpack('H',pack('A')))),pack +('C', unpack('%U*',unpack('B',pack('i')))-unpack('%b*',unpack('H',pack('A')) +)-unpack( '%b*',unpack('a',pack('A'))));
Introducing myself -featuring a JAPH
1 direct reply — Read more / Contribute
by Grimy
on Jun 03, 2011 at 13:05
    Howdy Monks!

    I discovered Perl exactly 3 days ago in the goal of writing a simple pre-compiler, because Flex compiler is really stupid (but that's another topic). I was instantly enthralled by this wonderful language, so much that I forgot my initial project and spent a sleepless night working on a JAPH. A common case, I suppose.

    Here's the result of this:

    #!/usr/bin/env perl -w -0466 use strict;use Digest::SHA open(F,$0),q\sha\.(($/=<F>)!~s?!.{50}!?!!?? 0:512);print+substr($/=sha512($/),$_,1)for(map{$!=95^ord;$%++%2?$!:map {64}1..$!}q!WU\x[c]T^|M~_j^Y]]_z_PTi]o_{^`\b_|^JWU^]_u^{_{\|[@!=~?.?g)
    It won't work as a one-liner: to run it, you have to store it into a file. Be careful when pasting however: adding a newline after the final parenthesis will break it (that's an obvious clue).

    Have fun!

    Arrgh! Woe, despair! My nice and pretty rows had been unspeakably split by the forum's felonious formatting! Now rewritting it to fit in 70 columns. EDIT: Done.

    PS: Please, be so kind as to let me know what you think about it.

\c*\c!\c0\c(
No replies — Read more | Post response
by ambrus
on Apr 25, 2011 at 18:36

    I know it's very simple, but I haven't seen this yet.

    print "\u\c*\c5\c3\c4\c`\c!\c.\c/\c4\c(\c%\c2 \u\c0\c%\c2\c,\c`\c(\c!c +\c+\c%\c2\cJ"

    This is, incidentally, no longer warning-free.

First JAPH!
1 direct reply — Read more / Contribute
by danltmz
on Apr 18, 2011 at 21:42
    This is my first JAPH, now that i just learn how to use pack & unpack:

    $_=join("|",unpack("a9 A15 Z9 a13",pack("a9 A15 Z9 a13","DJduZsztX","xADndoZtzhXexrD","dPZezrXlx","DHdaZczkXexrD")));$_=~s/d|z|x//gi;$_=~s/\|/ /gi;print;

    still very amateur, but I will continue practicing the art (:
(De-)Obfuscation for beginners
2 direct replies — Read more / Contribute
by cavac
on Apr 06, 2011 at 14:08

    I wrote a simple (and rather long, i admit) YAPH. The obfuscation isn't very good, either.

    And there's a reason for that: Most of the obfuscated code here on PerlMonks is very advanced. I wanted to give something to the community that can be de-obfuscated by a beginner... sort of training.

    Dear expert PerlMonks: Please don't post your de-obfuscated solution here; it'll spoil the fun for those who want to learn for themselfs ;-)

    Here's the code (yes, you absolutely need the Tk modules installed):

    If you have *any* trouble, just post it here - i'll try to talk you through.

    Don't use '#ff0000':
    use Acme::AutoColor; my $redcolor = RED();
    All colors subject to change without notice.
Just Another JAPH
1 direct reply — Read more / Contribute
by jarnolf
on Feb 27, 2011 at 12:58
    open(F,$0);$f=join('',<F>);close(F);@s=map{(map(chr,(index($f,join('' ,(map(chr,(41,41,41,46,46)))))..index($f,join('',(map(chr,(112,40,99) ))),index($f,join('',(map(chr,(46,46)))))),index($f,join('',(map(chr, (40,70,41))))),index($f,join('',(map(chr,(109,97,112,40))))))))[$_];} (9,20,18,19,26,0,13,14,19,7,4,17,26,15,4,17,11,26,7,0,2,10,4,17,27);; splice(@s,0,1,chr(74));splice(@s,13,1,chr(80));;$_=join('',@s);print;
    I cheated by doubling a couple semicolons in the last 2 lines to get the line lengths to match up.
binary parsing
2 direct replies — Read more / Contribute
by biohisham
on Jan 29, 2011 at 15:12
    My very humble first attempt at obfuscation.... Hope this can be an initiator for me into deeper unbeaten paths...
    print join(' ',map{unpack("A", pack("B8",$_)),''} qw( 01010000 01100101 01110010 01101100 00001010 01001101 01101111 01101110 01101011 01110011 00001010 01010010 01101111 01100011 01101011 01110011 00001010 ));


    Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

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.