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