[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
[FWP] Whitespace: the final frontier
This is probably an old idea, but its particularly twisted evil kept me amused for a couple of hours last night.
The idea came from a comment in O'Reilly's "Mastering Algorithms with Perl". In the section on steganography*, the authors suggest that it would be possible to write an arbitrarily complex program using only whitespace. The idea is as follows:
1. Write your program as per usual.
2. unpack the code into a binary representation
3. Convert the 1s to spaces and the 0s to tabs (or whatever)
And there you have it: a script neatly packaged away into whitespace! In order to run it, you just perform the steps in reverse, i.e.:
1. Convert the spaces and tabs (or whatever) back to 1s and 0s
2. pack to a string
3. eval the string
So, here's the script I wrote to convert Perl into whitespace. The script you want to be converted sits below __DATA__:
open FILE, ">evil.pl" or die;
select FILE;
undef $/; # Engage slurp mode, to get all of <DATA> in one string
print qq|eval pack sprintf("B%d",length),\$_ if chomp(\$_=<<_);\n|;
for (split//,<DATA>) {
$_ = unpack "B8",$_;
tr/01/ \t/;
print;
}
print "\n_\n";
__DATA__
#Your script here:
print scalar localtime time,"\n\n";
print "The following directories are on your path:\n";
print "$_\n" for split /;/,$ENV{PATH}
When run, it generates a file called evil.pl, which will look like this:
eval pack sprintf("B%d",length),$_ if chomp($_=<<_);
_
(N.B. In the interests of mail-friendliness this evil.pl is a non-functional sample only. Its second line really is just blank, rather than the 2300+ characters of whitespace that should be there.)
Now run evil.pl, preferably in the company of some friends/colleagues who think Perl is just a bunch of punctuation characters with a bad attitude, and watch the response. Hey, it worked for me!
By the way, you may have noticed that I omit the translate-whitespace-to-1s-and-0s step in evil.pl. I'll leave you to think about that one. :)
So, any suggestions for improvement, further obfuscation or saucy new features?
Cheers,
Mark
* [In case you're wondering (as I was, which was why I turned to the chapter :), steganography is the technique of hiding data within other data. Writing a seemingly innocuous paragraph where the first letter of each line spells a hidden message is stenanography, as is manipulating the low-order bits of binary image or sound data to contain a meaningful data pattern which won't be (immediately) visible to someone who isn't looking for it.]
__
Mark Whitaker
mark.whitaker@eml.ericsson.se
Tel: +44 (0)1925 883247
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe