Eccles & Toad home ~ blog ~ perl ~ projects ~ employ me
You are here: Home > Perl > JAPHs and obfus.

JAPHs and obfus

The following are my JAPHs which I have hacked together. Please remember that all proper coding standards have gone out of the window.

This solves Sudoku puzzles, as explained in this blog entry.

$a=8;$G{int(++$a/9).$a%9+1}=$_ for split//,<>;@A=1..9;sub c{int(($_[0]-1
)/3)*3}sub G{for$y(@A){for$x(@A){$p=$t=$G{my$c=$y.$x}&&next;$t.=$G{$_.$x
}.$G{$y.$_}for@A;for$f(1..3){$t.=$G{c($y)+$f.c($x)+$_}for 1..3}G($G{$c}=
$_)&&return for grep$t!~m/$_/,@A;return$G{$c}=0}}die map{$G{$_}}9..99}G

Three line version of the above, explained here.

use integer;@A=split//,<>;sub R{for$i(0..80){next if$A[$i];my%t=map{$_/9
==$i/9||$_%9==$i%9||$_/27==$i/27&&$_%9/3==$i%9/3?$A[$_]:0=>1}0..80;R($A[
$i]=$_)for grep{!$t{$_}}1..9;return$A[$i]=0}die@A}R

Simple translation confused by splitting the code into two columns.

$Z.='1021192000011415';$S.='$i="00";%A=map{$i++=>$_}(" ","a".."z");';
$Z.='2008051800160518';$S.=' $B.=$A{$_}for split/(..)/,$Z;"\n$B\n" ';
$Z.='1200080103110518';                 print eval $S;

More complicated JAPH - keep twiddling a random string until it is correct. Intended to run on *nix, but it should be easy enough to run on other platforms.

perl -e'@T=map{ord}split//,"Just Another Perl Hacker...";for(@T){push
@C,32+int rand 100}for(;;){$s=S(@C)||last;$r=rand 27;$c=rand>0.5?1:-1;
$C[$r]+=$c;$n=S(@C);$C[$r]+=($n==$s+1?1:2)*-$c if$n>$s;print map({chr}
@C),"\n"}sub S{$t=0;for(0..27){$v=$_[$_]-$T[$_];$t+=($v>0?$v:-$v)}$t}'