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