Obfuscated PERL.


One of the principal applications that Perl excels at, is in its use for decoding character strings. In order to decode these strings of character data, there are easy ways to write PERL code, and hard ways. One of the hard ways is to write the PERL code in a very compact form, with non descriptive variable names, deliberately abbreviated to make the code even smaller in size. This type of PERL coding is often known as Obfuscated PERL, although the examples indicated here, could arguably be called just very minimal applications. Now whilst this type of code is a triumph in minimalism, it is not generally a good idea to use it in general Perl coding, because it is nigh on unintelligible.

Two examples of this highly compact style of coding are shown here, both of which are absolute coding masterpieces, but rather hard to follow for the uninitiated. The first example is in the C programming language, to allow it to be contrasted against PERL:

C Code.

The following C code is the Hannum-EFDTT C source code.

/* efdtt.c Author: Charles M. Hannum */
/* Usage is: cat title-key scrambled.vob | efdtt >clear.vob */
#define K(i)(x[i]^s[i+84])<< unsigned char x[5],y,z,s[2048];main(n){for(read(0,x,5);read(0,s,n=2048);write(1,s,n))if(s[y=s[13]%8+20]/16%4==1){int i=K(1)17^256+K(0)8,k=K(2)0,j=K(4)17^K(3)9^k*2-k%8^8,a=0,b=0,c=26;for(s[y]-=16;--c;i/=2,j/=2)a=a*2^i&1,b=b*2^j&1;for(j=127;++jy)a^=a>>14,a=a>>8^(y=a^a*8^a<<6)<<9,b=b>>8^(z=b^b/8^b>>4^b>>12)<<17,i=s[j],i="7Wo~'G_\216"[i&7]+2^"cr3sfw6v;*k+>/n."[i>>4]*2^i*257/8,s[j]=i^(i&i*2&34)*6^z+c+~y;
}}


PERL Code.

The following PERL code is the QRPFF PERL source code.

#!/usr/bin/perl -w # 531-byte qrpff, Keith Winstein and Marc Horowitz # MPEG 2 PS VOB file on stdin -> descrambled output on stdout # arguments: title key bytes in least to most-significant order # qrpff 153 2 8 105 225 < /mnt/dvd/VOB_FILE_NAME | extract_mpeg2 | mpeg2dec - $_='while(read+STDIN,$_,2048){$a=29;$b=73;$c=142;$t=255;@t=map{$_%16or$t^=$c^=( $m=(11,10,116,100,11,122,20,100)[$_/16%8])&110;$t^=(72,@z=(64,72,$a^=12*($_%16 -2?0:$m&17)),$b^=$_%64?12:0,@z)[$_%8]}(16..271);if((@a=unx"C*",$_)[20]&48){$h =5;$_=unxb24,join"",@b=map{xB8,unxb8,chr($_^$a[--$h+84])}@ARGV;s/...$/1$&/;$ d=unxV,xb25,$_;$e=256|(ord$b[4])<<9|ord$b[3];$d=$d>>8^($f=$t&($d>>12^$d>>4^ $d^$d/8))<<17,$e=$e>>8^($t&($g=($q=$e>>14&7^$e)^$q*8^$q<<6))<<9,$_=$t[$_]^ (($h>>=8)+=$f+(~$g&$t))for@a[128..$#a]}print+x"C*",@a}';s/x/pack+/g;eval

Links.

Similar code masterpieces of minimalism
The same minimalism masterfully converted to an executable prime number
http://www.cgi101.com/class/ch3/text.html


www.cyberthinc.com