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