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;

In reply to Generating JAPHs by tsee

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.