[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] First Attempt at Massive Obfuscation



It won't win the Obfuscated Perl Code Contest, but what does this code do,
and why:

#!/usr/bin/perl

$num = 128;


$z = 20;$lowZ = 0;$highZ = 40;
while (1) {
 print "count = $count\nSTARTING LOOP -- z is $z...";
 $count = 0; $x = $num; $y = $num;
 while (1) {
  ($x, $y) = ($x ** $y, $y ** $x);
  goto LOWER if ($x eq 'Inf' or $y eq 'Inf');# might this break on most
systems?
  goto HIGHER if ($x == 1 or $y == 1);
  exit print "$z\n" if (++$count > 10000);
  $x = $x ** $z; $y = $y ** $z;
 }
 LOWER: print "high..."; $highZ = $z; $z = ($z+$lowZ)/2;	next;
 HIGHER: print "low..."; $lowZ = $z; $z = ($z+$highZ)/2;	next;
}
__END__

And, can anyone obfuscate it some more (ok, I know the answer to that :)


For spoiler, see below...




































(watch out! spoiler comming soon!)



(run! hide!)


The code calculates $num ** -1.

It does a divide-and-conquer binary search by changing the value of z. The
calculation it performs is

	x = (x**x)**z

x will only stay within the limits of FP precision if it doesn ot grow
(because if it grows, it will eventually become infinite) or shrink (in
which case it would eventually become 1). The only way x stays the same is
if z = (1/x), becayse then the exponents cancel.



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe