use strict; use warnings; my $plaintext = 'We are discovered. Flee at once!'; my $key = 'CorrectBatteryHorseStaple'; print "Original message: $plaintext\n"; my $ciphertext = pack('u',cypher($plaintext,$key)); print " Encoded message: $ciphertext\n "; my $decoded = cypher(unpack('u',$ciphertext),$key); print " Decoded message: $decoded\n"; sub cypher { my $plain = shift; my $key = shift; my $i=0; my $j = length($key); return join '', map {$_^substr($key,$i++ % $j,1)} (split '',$plain); }