A few days ago, i released an obfuscated Tk YAPH, where most of it was Base64 encoded in some sort of figlet code.

Turning the program into the base64 figlet text was done by a... you guessed it: Perl script. Since i though that writing a Perl script to obfuscate another Perl script was kinda cool, it would be sad to let it rot on my harddisk. So i rewrote it to make it more useable and even added comments for your reading pleasure.

And here it is:

#!/usr/bin/perl # This is the legendary figlet encoder that turns every text file # into a BIIIIG base64 encoded message. # # It works, because MIME::Base64 ignores whitespace and anything after # the end-character (which is an equal sign) on decoding. use strict; use warnings; use MIME::Base64; # Change this if you don't like Edgar Allan Poe my $bigtext = "Once upon a midnight dreary, while I pondered weak and +weary, Over many a quaint and curious volume of forgotten lore, While + I nodded, nearly napping, suddenly there came a tapping, As of some +one gently rapping, rapping at my chamber door. 'Tis some visitor,' I + muttered, 'tapping at my chamber door - Only this, and nothing more. +' Ah, distinctly I remember it was in the bleak December, And each se +parate dying ember wrought its ghost upon the floor. If you can read +this text, you did not change the BIGTEXT variable in the figlet enco +der example as instructed."; # Check the command line options and use some named variables for the +filenames if((scalar @ARGV) != 2) { die("Usage: figencode_full.pl inpufile outputfile"); } my ($infile, $outfile) = @ARGV; # Turn our text into "figlines" my @figlines = `figlet -w 70 -f banner "$bigtext"`; # Slurp and base64-encode our file open(my $ffh, "<", $infile) or die($!); my $figtext = encode_base64(join('', <$ffh>), ''); close $ffh; # split the base64 encoded file into single characters # for easier handling my @figparts = split//, $figtext; # We'll need some "simbytes" to fill up unneeded space with simulated +base64 my @simbytes = split//, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS +TUVWXYZ0123456789"; # Let's also count "wasted" bytes my $overbytes = 0; # Now, we're nearly ready to go open(my $ofh, ">", $outfile) or die($!); # Iterate through all "figlines" foreach my $line (@figlines) { chomp $line; # Work on the lines byte-by-byte my @parts = split//,$line; foreach my $part (@parts) { # whitespace will stay whitespace if($part eq " ") { print $ofh " "; } else { if(@figparts) { # if we still have some real base64 values, output tha +t my $tmp = shift @figparts; print $ofh $tmp; } else { # else just simulate raw data to confuse the reader my $tmp = $simbytes[int(rand(scalar @simbytes))]; print $ofh $tmp; $overbytes++; } } } # at the end of the line we print out an end-of-line character. We +ird, huh? print $ofh "\n"; } # Yeah, we're done writing close $ofh; # Now, let's inform the user, if it actually works # (and how much figlet-bytes (s)he wasted with simulated bytes) if(@figparts) { print "Lost " . (scalar @figparts) . "bytes in translation!!!\n"; } elsif($overbytes) { print "Wasted $overbytes figlet bytes!\n"; } else { print "Length is perfect.\n"; }
Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.

In reply to Nicer Base64 encoding by cavac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.