#!/usr/bin/perl -w # shift_encode.pl - Don Yang (uguu.org) # # Encode text using constants found with shift_constants.c use strict; use constant BOUNDARY => 40; use constant MUL1 => 3; use constant MUL2 => 255; use constant SHIFT => 158; # Build translation table my %table = (); for(my $y = 33; $y < 127; $y++) { next if $y == ord('\"') || $y == ord('\\'); my $x = ($y * ($y < BOUNDARY ? MUL1 : MUL2) + SHIFT) % 256; push @{$table{$x}}, $y; } # Build indices so that we alternate between choices for the same # input character, where available. In practice, there is usually # only one choice. my %index = (); $index{$_} = 0 foreach keys %table; # Encode input my $input = join '', <>; foreach my $c (unpack 'C*', $input) { die "No translation for $c\n" unless exists $table{$c}; print chr($table{$c}[$index{$c}]); $index{$c} = ($index{$c} + 1) % (scalar @{$table{$c}}); }