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$..$/