#!/usr/bin/perl -w # table85.pl - Don Yang (uguu.org) # # 07/29/12 use strict; # Assuming that this formula will be used for decoding: # orig = (encoded + shift) % mod; # # Compute appropriate values for "shift" and "mod" such that all values # in [0..84] can be covered without using escaping characters. sub FindDecodeParams() { for(my $shift = 0; $shift < 256; $shift++) { for(my $mod = 85; $mod < 94; $mod++) { my %uniq; for(my $c = 33; $c < 127; $c++) { next if (chr($c) eq '"' || chr($c) eq '\\'); $uniq{($c + $shift) % $mod}++; } my $accept = 1; for(my $i = 0; $i < 85; $i++) { unless( exists $uniq{$i} ) { $accept = 0; last; } } if( $accept ) { print "shift=$shift, mod=$mod\n"; } } } } # Output decode table to stdout sub OutputTable($$) { my ($shift, $mod) = @_; for(my $i = 33; $i < 127; $i++) { next if (chr($i) eq '"' || chr($i) eq '\\'); my $o = ($i + $shift) % $mod; next if( $o >= 85 ); printf '%03d %c -> %03d'."\n", $i, $i, $o; } } OutputTable(83, 89);