In my earlier submission I showed a means of JAPHing using a polynomial generated by Excel. Here now is some code to calculate the equation from a string all in Perl.

It works fine with the JAPH string upto 19 characters above which I think the limitations on internal maths stuff breaks. It's not obfusctation at this point and suggestions to get it work with the full 25 characters in JAPH (include line feed) would be fun. Note the code has been cobbled together on a Friday afternoon and I've made no attempt to make it elegant

#!/usr/local/bin/perl -w use strict; use Math::Polynomial; my %h = (); my $s = "Just another Perl h"; # put string into a hash {0=>J, 1=>u ...) map { $h{$_}=ord(substr($s,$_,1))}(0..length($s)-1); # use the library to get the polynomial factors my @p = split / /, Math::Polynomial::interpolate(%h); # generate the calculation string from factors my $p; my $i = length($s)-1; map{ $p .= "+$_*\$i**$i";$i-- } @p; # tidy the string, remove $i**0 (=1) # add .5 to total for rounding purposes $p =~ s/\+\-/\-/g; $p =~ s/.*\(//; $p =~ s/\).*/.5/; print "$p\n"; # test the equation for $i (0..length($s)-1) { print chr eval $p; }
Update

Links and spelling corrected as per chatterbox