#!/usr/bin/perl -w # encode_code.pl - Don Yang (uguu.org) # # 05/11/09 use strict; use Compress::Zlib; # Compress input and remove whitespaces my $input = join "", <>; my $data = pack 'u', compress($input, 9); $data =~ s/\s//sg; # See if there are any backslashes in the input. If not, we don't # need any clever escape magic (reduces the stub by 35 bytes). This # is rarely worth the effort, but sometimes we get lucky. my ($open, $close); if( index($data, '\\') < 0 ) { # No backslash $data = "q{$data}"; $open = "{"; $close = "}"; } else { # Transformation to remove backslash. # # Alternatively, we could have done 's/\\/\\\\\\\\/sg', but it # doesn't look as nice. It would also make us not able to break # the output string at arbitrary positions. my $transformed_data = join "", map {chr($_ + 3)} unpack "C*", lc $data; $data = 'uc(join"",map{chr($_-3)}unpack"C*",q!' . $transformed_data . '!)'; $open = "["; $close = "]"; } print '($z=q', $open, 'usezCompress::Zlib;', 'eval(uncompress(unpack("u",', $data, ')))', $close, ')', '=~s/\s//sg;', '$z=~s/z/ /;', 'eval$z;', "\n";