#!/usr/bin/perl -w use strict; use warnings; my %p2C; my %C2p; sub key { my $kp= shift; my $caesar= shift; my $a=0; my $k; $p2C{' '}=' '; $C2p{' '}=' '; foreach (split(//, $kp)) { if (not exists $p2C{$_}) { #print $_; $k=chr(ord('A')+(($a++)+$caesar)%26); $p2C{$_}=$k; $C2p{$k}=$_; } } foreach ('a'..'z') { if (not exists $p2C{$_}) { $k=chr(ord('A')+(($a++)+$caesar)%26); $p2C{$_}=$k; $C2p{$k}=$_; } } } sub printKeys { my $href = shift; print "\nCT: "; print(($_).' ') foreach (sort keys %{$href}); print "\npt: "; print(($$href{$_}).' ') foreach (sort keys %{$href}); print "\n"; } key ('thequickbrownfoxjumpsoverthelazydogs',10); printKeys(\%p2C); printKeys(\%C2p); print "----------------------------------------------------------\n"; undef %p2C; undef %C2p; key ('thequickbrown',10); printKeys(\%p2C); printKeys(\%C2p);