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