A few months ago, I was in the middle of another Perl project, and on an impulse took time out to try something new. As is often the case, I didn't expect it would take more than a few days to finish it.
Many weeks later, I have this obfuscation to show for it:
use Tk ; ($ "= q \$ +;
W) i(s -9o ),B )$,} n$ p90)=2+$
m$sdnr 0,;/)$,=w uo,ix+((; E,s)bw$
n3&" -())h=N -ot/9x?$} ?i(A>,fg
0"[xp (f"{n$"; ,e0,u$t" meP#$4q-$
s1|,yw," J5$9yhe|J( ;$ .=,Z])@q3 ($ $O"~9)+=B"
;1fM,%s0&)(,*@,,-$0/ :&($H"F4$>k2#2n[v()=)t
a)xp4e:,$?@))f="/0xx $b$A;=t@x1,t]I,2Rm@e$3
0-;?)$:Ga_r_,09i)} B1Vp;(;A,0f(},/;{$1$(2
:(-$$$@(f0V041" ?Me2F"+0-,02.[-,:="r=>2
,0"0>$1sea>d 5 7,e-uF;pqnse52-q9p,$l$dul
):3$]d1liW(b e,20Z+a)=t)${tA8:))t;("otd
e(04{?e($&r -o(0,0p/($U"$${$,-,u;)b=,W
f$k 27-s(;,~".) V)5 26h"$$/9=}=;5x0@:HB^0"s$f)4
:B";)(,,uMo,/6,e p=[3" b-rAg0Hqu(a6;N>((;,($s$-0
$PC$0$-$shez,W {aj,J6 b) @,]9.mn=2 =0,aS$+0=yv05~
:$n,F):s(a;5s 4B d$)/6p $s$ )/0,(H}i0 rq (j;#,$$;(),
i,-<@h-cPp0?-n$h@_/3,,u.09 treA=80$$s.:0f ),;s0 :Cd
h@$:"=6$p,7,)@UU6%@4jl301=I-;0d_0+i2,)(,1$ ,*;,+t0 9;1
$)r9%(-)",0n,A}=0.$w{,6:e$}(s:3ri$"01xP@0 q1f*,
Z,:4t)F.r2"c6=$20};;.t0,o4$J4,$$p@(,Js0A;0
+sPrA$9($,[$,&=|i-s00q-$x-3$|n1*:,,bj=66c=
t)$63$g]$00-1$}s06r=;Xx,$;/@+,0*>$=54bw;
$$-)s"bs/5;h&HS9,ib=hg,$i_;*0Anl$i;9Sl(
$$:($anf$0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 3/}rFsx@i)7u$0@();,
, Bn=5sa,A$-$($=t(:h,9)u 1M[y(($8@$0*,,=*,)A
b0C _:($ 1M/ $;(+,,[3 $s )a]vm@$7$0 8O,;i),a
_D5Y]0-$( n ($p),:=} , $P$W.I{\ )=~s"[
$/ ]""g ;map{$h{$_} .=substr $",0
,1,""} split//, crypt(qw/ FRaCtal:
/, q+rp +)x160; $_=join //,map
{$h {$_ }} sort keys %h ;s /N
/ /xg; eval #l iv er po le
The purpose of the program (if peek you must) is ...
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
|
#!/usr/bin/perl -w
#justanotherperlhacker
use strict;
open*_,$0;<_>;
(y,#,,d,s,t,t ,,s,r,r ,,s,l,l ,,y,j,J,,y,p,P,,s,$,.,,print,goto'')
for<_>
... and another happy little comma lives over here.
Not particularly obfuscated, but I think it's enough to initially confuse someone who isn't paying attention. It does use a few fun tricks, though, and it passes warnings and strictures.
|
Not exactly on obfuscation, but I didn't know where else to put it... Warning: neither __END__ nor @data can be used anywhere in the programs in question, lest it will fail.
#!/usr/bin/perl
use strict;
use warnings;
die("File does not exist.\n") unless -e $ARGV[0];
open(QUINE, "+<", shift);
my @quine = <QUINE>;
push @quine,
'my @data = <DATA>;'."\n",
'print @data, @data'."\n",
"__END__\n";
push @quine, @quine;
seek(QUINE, 0, 0);
print QUINE @quine;
close(QUINE);
my @data = <DATA>;
print @data, @data
__END__
#!/usr/bin/perl
use strict;
use warnings;
die("File does not exist.\n") unless -e $ARGV[0];
open(QUINE, "+<", shift);
my @quine = <QUINE>;
push @quine,
'my @data = <DATA>;'."\n",
'print @data, @data'."\n",
"__END__\n";
push @quine, @quine;
seek(QUINE, 0, 0);
print QUINE @quine;
close(QUINE);
my @data = <DATA>;
print @data, @data
__END__
|
This may be better posted in Meditations. It sort of touches on both ponderings and obfuscations. I was prototyping an algorithm the other day when I developed a rather obfuscated method for building a hash from two lists. While this is not exactly a full "obfu", I certainly think the behavior could be incorporated into a full obfu. This seems to actually get in to the "what the heck is happening here?" as ysth, gryphon, and especially diotalevi have commented on perverseness of the construct. Without further ado:
push( @{ $y{ ($a = $_, ( grep {$a=~/$_/} @t )[0] || next)[1] } }, $_ )
+ for @f;
The intent of this code is to take a list of patterns and a list of strings and group the strings based on pattern. It also needed to disregard any string that did not match any pattern.
In larger context, this line came from a bit of prototype code I was working on that was
use strict;
my @t=qw(one two three);
my @f=qw(
one.ind.01 one.ind.02 one.tab.01
two.ind.01 two.tab.02 two.ind.02
three.ind.02 three.ind.01 three.tab.03
four1.ind four2.ind four2.ind
f1v.ind.31 f1v.ind.32 f1v.ind.32
);
my %y;
push( @{ $y{ ($a = $_, ( grep {$a=~/\b$_\.ind/} @t )[0] || next)[1] }
+}, $_ ) for @f;
All monks previously mentioned (as well as others), were immediately revolted by such "offensive" code. diotalevi went on to say "Please tell me that you have never committed any code that actually looked like that!" He then went off to try to decipher how it actually worked. I do not think he ever found a satisfactory answer other than the next is a near-no-op with stack manipulation.
The line in question can be re-written in a much more verbose way:
So, what are the thoughts of other monks regarding this obscure construct? Perhaps more importantly, what does the Perl development community say about the behavior (both internal and external)? Is this asking for a future incompatibility? Is it firmly grounded or did I stumble on something that should not work?
Ivan Heffner
Sr. Software Engineer
WhitePages.com, Inc.
|