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
Fibonacci numbers using regexes (threes are wild)
2 direct replies — Read more / Contribute
by blokhead
on Oct 15, 2009 at 12:18
    perl -le'$;=3;$;=~s/./$&?30:3/eg for 3..pop;print length$;' 12
    Replace command-line argument 12 with any positive integer N to get the Nth Fibonacci number. Starts getting pretty slow for me after N=30, by the nature of the algorithm.

    Can you see how it works?

    blokhead

JAPH with only goto (and some noise)
3 direct replies — Read more / Contribute
by haoess
on Oct 09, 2009 at 04:41
    perl -we 'goto qq.\010.x0x11.qq.Just another Perl hacker,\n.'

    -- Frank

map based JAPH
No replies — Read more | Post response
by vitoco
on Oct 08, 2009 at 13:02
    print(map{chr}(map{$/=$_+$_[$;-!$_];$;=$_?++$;:$_*($/=32); $/-32*!($.++%13)}map{-46+ord}split//,q,0B>7.';:71!&.62=/., ),@_[$~..5],44)if$;=$.=$~=0or@_=map{ord}split//,q;hackerz;
Simple signature
No replies — Read more | Post response
by markkawika
on Sep 21, 2009 at 15:52

    This is my first attempt at obfuscated Perl. It really rubbed me the wrong way to write it, since I'm such a stickler for maintaintable, readable code. I currently use this as my .signature.

    perl -le '$"=$,,@_=(1)x4,@a=(0,4,5,4),map{$_<<=6,$_+=13}@_;for(0.. 3){$_[$_]+=1<<$a[$_]if$_;$_[$_]+=$a[$_]}$_[3]+=10,print map chr,@_'

    I worked pretty hard on getting it as short and obfuscated as possible. There's a neat trick I used in there with the @a array. It happened to work out mathematically in my favor.

    I welcome feedback and/or improvements. :)

Obfu challenge! What is it?
No replies — Read more | Post response
by corenth
on Sep 17, 2009 at 21:03

    UPDATE 9/21/2009

    Wow. this is a real reminder of how easy it is to fall prey to your own certainty. I tested my script on a couple of cases, and they turned out fine, so I assumed that all was well. I tried a new case and found that "something" was wrong. I fixed that something and was happy. I never bothered to test any other cases until later. OOPS! I have been running several cases after making my final adjustments. I believe that NOW the script solves all problems it's designed too. I AM crossing my fingers on this, but it looks like I've repaired all my bits. (pun absolutely intended- also a hint)

    Well, not quite. There is one case that it does solve, & I don't know why that is... maybe someday I'll get it. As it is, I'm putting adjusted code in a less obfuscated manner bacause I'm a tad too lazy to worry about it...

    Big UPDATE:

    I left out a key peice of code in the obfuscation. The output was incorrect for the lack of that code. Now that it's in there, all problems of the sort that this code solves should be solved unless I hade any other errors in logic *sigh* Of course, if you have the non-corrected code, you might gain some insight from comparing the two versions.

    I have three some challenges with this obfuscated code:

    1. Can you figure out the purpose of this code?

    2. What ways can the code be obfuscated further? I've never done this before, and haven't quite gotten the hang of it.

    3. What metaphors do you think I've used? I use the term to refer to things like how I might visualise the data (tables, lists, objects) or how I perceive the problem (is it recursive, is A the function of B, is "brute force" used to solve a problem, or perhaps a genetic algorithm).

    4. Better code? Keeping the metaphors you think I'm using, how can I optimize it to run faster?

    5. Why is there a leading white space in the output- must be in there somewhere.. I've no idea..

    Hints:

    There are some optimizations that I have not used in order to keep with one "metaphor" that I'm using.

    The problem I'm solving has been golfed before. This is DEFINITELY not a golf! I don't know about obfuscations.

    The output needs to be formatted to make it recognizable to someone who knows this kind of problem. Also, while the problem's solved, the output values are not what's expected of solutions to this type of problem.. Update: Perhaps I should say that the output itself is slightly obfuscated. Correct output would by way too obvious.

    As I said before " it looks like I've repaired all my bits" - pun and hint all in one!

    I really don't know if this is going to be an easy task or an impossible one. If it's too difficult I will have to add hints. If I had to solve a puzzle like this, I'm not sure that I could.

    Update: perl -v gives This is perl, v5.8.3 built for ppc-linux-thread-multi on my system. I doubt this will be an issue for anyone else. Good Luck!
Linux console japh
2 direct replies — Read more / Contribute
by ambrus
on Sep 05, 2009 at 08:41

    Run this on linux text console only. It won't work in an xterm or similar. (Update:) This looks better if you stand far from the monitor.

    clear;perl -we 'ioctl STDIN,19296,$t=pack a8888;while(++$o){select""," +","",0.01;print"\e[H";for$v(0..19){$x=0.5*$_+3e-2*$v*($_-39)+0.5*$o,p +rint vec($t,8-$x%9+8*int(0.9*$v+1.5-3e-3*($_-39)**2)+256*ord substr(" +Just another Perl hacker ",$x/9%26),1)?"#":" "for 0..78;print$/}}'

    This is a reimplementation of a japh I have written and lost long ago. Speed depends on the speed of your computer somewhat.

Perl 6 bitwise
1 direct reply — Read more / Contribute
by carlin
on Aug 24, 2009 at 21:18
    Just something I threw together together while playing with Perl 6's bitwise operators. Haven't really tried to golf it and the obfuscation is fairly obvious. Runs fine under Rakudo, haven't tested any other implementation.
    my $s=' ';say 'N'~&'K','t'~|'a','w'~&'s','v'~&'u',$s,'i'~&'e','l'~|'b' +,'m'~|'b','p'~|'d','x'~&'i','g'~&'m'~'z'~&'s',$s,'c'~&'v','o'~&'y','p +'~|'d','v'~|'a','m'~&'y','r'~|'a','d'~|'a',$s,'n'~|'a','c'~&'z','d'~| +'b','t'~|'a','r'~|'a','b'~|'a','i'~&'c','v'~&'u','k'~&'y','n'~|'a','l +'~|'b';
    Tip: ~| is | in Perl 5 and ~& is & in Perl 5.
My latest JAPH
1 direct reply — Read more / Contribute
by jh-
on Jul 15, 2009 at 04:44

    Hi,

    I had some free time and I was bored, so I decided to hone my Perl-fu with my second ever JAPH. It's quite simple, but I think it looks neat and I had lots of fun doing it. I had the chance to test it only with Perl 5.8.8, but I think hope it'll work with 5.10 too.. At least I can't see why it wouldn't.

    To run it, place it in any file and make sure there are no empty lines before the first actual code line.

    $"="032";($:=++$|)*=4;open+0;sub #074117115116 _{$_=<0>;~/.*#(.+)(?{$,.=$+.$" #097110111116104101114 ;$:--?_():0})/}_;$,=~s/.$//; #080101114108 map{print chr}$,=~/(...)/g #104097099107101114046010

    (fixed, should work with 5.10 now. Thanks wazoox!)

    If anybody wants me to, I can post a de-obfuscated version or some commentary, but I hardly think it's necessary.

    Please let me know what you think! :-)

binomial coefficient
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 05, 2009 at 09:05
    I am out of ideas to get this smaller,but I feel it can. _ calculates it recursive and __ does a direct calculation.
    sub _{($:,$,,$;)=@_;$;=$;?$;:1;($:>$,)?_($:-1,$,,$;*$:/($:-$,)):$;;} sub __{($:,$;)=@_;$;++;for($,=1;$:>$;;$:--){$,*=$:/($:-$;)}$,;};
Play with numbers
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 04, 2009 at 12:55
    An script I wrote, which outputs Japh. It decrypts $x by multiplying 2 integers and the act like it is a binary number. The code isn't really exciting, but the way I encoded 'Japh' is kinda interesting.
    $x = '3336703366667337000033670003' ;$d=sub {chr unpack('N',pack ( 'B32',substr(('0'x32).((shift) * (shift)),-32) )) ;};print ${ dx( $d, $x) }; sub dx{ while ( $_[1]=~/(\d{6})(\d{1})/g){$out .= &{ $_[0]}($1 ,$2); }\$out;}

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.