My good friend chargrill recently posted this excellent obfuscation, demonstrating a famous method of encryption called the "Playfair Cipher".

I thought it would be fun to write an obfuscated "Playfair decryption", and since chargrill told me it was fine with him, and because today is my one-year anniversary at Perlmonks, I wanted to submit it by the end of the day.  (Just barely made it!)

It runs under Windows.  (I had intended it to work with Linux as well, but the "table" doesn't update quite right yet).  The 3 parameters it takes (which can be "hardwired" at the top of the script) are:

  1. The delay factor ($d), in fractions of a second.  This defaults to no delay at all, which is fast but less fun to watch, as it doesn't visually update as it decrypts.  A suggested value is between 0.01 (quite fast) to 1.0 (very slow)
  2. The table "key", used in populating the table ($t).  It defaults to the value used in the original obfuscation.
  3. The encrypted text ($e), which defaults to the encrypted output from the original obfuscation.
$d = shift; $t = shift || "ocumentsadigjrkplhxbfqvwy"; $e = shift || "slobxtfqnrgmpfbukgadarsotxdvaweoaggoodmgfbngnidculipvcm +dtnmrasbuopjagqgnmktxnkjknxvjehasgncspntopfbugabutubueomrnjsfoddcnkdp +qexsgxudvxmdsancdohedlmdjaslodraocqpminbxtfqnrxmpuxicecndkslomdunoslo +upfbugabudculipvcmbodmgfbsaxngknuqpcdlamkangjxrlxnjtadcdnnonjtibcbcal +dcjadapisludrolhudehasgncspntopfbuxrtnxrslmkeckmucoxbchwgjodmkoupfbuj +avddcuaslodpisjcdbulhdwwngkjnslsjhagjipopmttsbqxskamkncxkmdjdpiuosloy +kmvcodeqdttxvdjnsjdkonjarolhudehasgncspntopfbujaneudinaqmirygnpjal"; ($a,$b)=eval{ require Win32::Console::ANSI}?(30, "4;7"):(100,"");$p={map{$_,[int$k/5,$k%5,$k ++]} split//,uc$t};$P={map{@_=@{$p->{$_}};$_[0].$_ [1 ] =>$ _ } keys %$p }; sub w($){ (4+ pop )%5} p ( "\e[$b;${a}m\e[2J") ;sub p{printf@_}sub P{select $A,$A,$A,$d if$d}sub c{my($c,$t,$f,$x,$y)=@_ ;if ($f){$x =3*$x+2 ;$y =3*$y+2;map{$q=$_;map{(2==$q &&2==$_)or c($c,' ',0,$x+$_,$y+$q)}(-1..1)}(-1.. 1)}$d && p"\e[%d;%dH\e[$b;%dm$t",$x,$y,$c+$a}map c(6,$_,1,@{$$p{$_}} ),keys% $p;p"\e[17H\e[%dm",$ a+5;p"$e\e[17H\e[s" ;P; sub l{( $u,$ v) =split// ,pop;($u,$U) =@{$ $p{$u }};($ v,$ V)=@ {$$p{$v}} ;$ h =sub {($ J,$ C,$N )=@ _;c($J,$P->{$C.$N},1, $C,$N)};($w,$W,$z,$Z)=($u==$v)?($u,w$U,$v,w$V):( $U==$V)?(w$u,$U,w$v,$V):($u,$V,$v,$U);$h->(1,$u, $U);$h->(2,$v,$V);P;$h->(6,$u,$U);$h->(6,$v,$V); $h->(1,$w,$W);$h->(2,$z,$Z);P;$h->(6,$w,$W);$h-> (6,$z,$Z);p"\e[u\e[%dm%s\e[s",$a+3,$P->{$w.$W}.$ P->{$z.$Z}}{l(uc substr($e,0,2,"")or last),redo}

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Playfair Decryption by liverpole

Title:
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.