#!/usr/bin/perl -w if( $#ARGV < 0 ) { die "$0 \n"; } ($key = shift) =~ s/[^a-zA-Z]//g; @offsets = map {$_ < 91 ? (91 - $_) % 26 : $_ - 97} unpack 'C*', $key || 'a'; for($offset = 26; $offset--;) { for($input = 256; $input--; $translate{$input}{$offset} = $input) {} for($input = 26; $input--;) { foreach (97, 65) { $translate{$_ + $input}{$offset} = $_ + ($input + $offset) % 26; } } } for($index = 0; <>;) { foreach $i (unpack 'C*') { ($c = chr($translate{$i}{$offsets[$index]})) =~ /[a-zA-Z]/ && $index++; $index %= $#offsets + 1; print $c; } }