In a bored moment about two years ago, I wrote a script to encode my custom messages in an obfuscated script, JAPH style. The code is horrible, alright, but it works (except the simple-minded line wrapping). Enjoy:
It encodes stuff like this:
___ __
| /\ | \ | |
| /__\ |__/ |---|
\_/ / \ | | |
as: (with some manual linme wrapping thrown in for measure)
@n=([1032,168],[33598800,50428013],[228994128,52434173],[1088485074,
50427365]);$b=6;@c=' -/\\_|'=~/./g;for(@n){for$n(@$_){map{$h=int$n/$b
**$_;$n-=$b**$_*$h;$c[@c]=$h}reverse 0..12;push@p,map{$c[$_]}@c[
reverse$b..$#c];$#c=$b-1}$p[@p]="\n"}print@p;
Here's the offending script:
#!/usr/bin/perl
=head1 NAME
A simple encoder/obfuscator
=head1 SYNOPSIS
encode INPUT_FILE
=cut
use strict;
use warnings;
use Pod::Usage;
$ARGV[0] or pod2usage("First argument must be input file!");
open my $fh, $ARGV[0] or pod2usage("Could not open file '$ARGV[0]': $!
+");
my @lines = <$fh>,
close $fh;
chomp @lines;
my $code = join '', <DATA>;
my %unique = map { ($_, undef) } map { ( split // ) } @lines;
my @chars = map {$_ eq "'" ? "\\'" : ($_ eq "\\" ? "\\\\" : $_) }
sort keys %unique;
my $base = @chars;
$code =~ s/BASE/$base/;
$code =~ s/CHARS/join '', @chars/e;
my $i = 0;
$unique{$_} = $i++ foreach sort keys %unique;
my $limit = -1;
foreach my $line (@lines) {
my $no = 0;
my $cur_base = 0;
foreach my $char ( split //, $line ) {
$no += $base**$cur_base++ * $unique{$char};
if ( $no >= 2**31 ) {
$cur_base--;
$limit = $cur_base if $cur_base < $limit or $limit <= 0;
$no = 0;
$cur_base = 0;
redo;
}
}
}
$code =~ s/LIMIT/$limit - 1/e;
my @outer;
foreach my $line (@lines) {
my @inner;
my $no = 0;
my $cur_base = 0;
foreach my $char ( split //, $line ) {
$no += $base**$cur_base++ * $unique{$char};
if ( $cur_base == $limit ) {
push @inner, $no;
$no = 0;
$cur_base = 0;
}
}
push @inner, $no;
push @outer, [@inner];
}
@outer = map { join(',', @$_) } @outer;
my $stuff = join '],[', @outer;
$code =~ s/STUFF/$stuff/;
@lines = split /\n/, $code;
my $line = 0;
$i = 71;
while ($i > 0 and length($lines[$line]) > 72) {
if (substr($lines[$line], $i, 1) eq ',') {
my $str = $lines[$line];
splice @lines, $line, 1,
substr($str, 0, $i+1), substr($str, $i+1);
$line++;
$i = 71;
}
$i--;
}
print join "\n", @lines;
__DATA__
@n=([STUFF]);$b=BASE;@c=
'CHARS'=~/./g;for
(@n){for$n(@$_){map{$h=int$n/$b**$_;$n-=$b**$_*$h;$c[@c]=$h}reverse 0.
+.
LIMIT;push@p,map{$c[$_]}@c[reverse$b..$#c];$#c=$b-1}$p[@p]="\n"}print@
+p;