Basically you want something along the lines of:
# # Warning: untried code # my $message = "Blah!"; my (%translation); my $alphabet = join('', (a..z)); # Cheezy, but does 2 passes, performing a uc() in between foreach (0..1) { my $startchar = ord(substr($alphabet, 0, 1)); foreach my $c (0..25) { $translation{chr($startchar + $_)} = substr($alphabet, $_ - 13, 1); } $alphabet = uc($alphabet); } # %translation now contains the value for each character # in ('a'..'z', 'A'..'Z') print("Old message: ", $message, "\n"); my @letters = split('', $message); my (@newmessage); while (@letters) { my $c = shift(@letters); $c = $translation{$c} if (defined($translation{$c})); push(@newmessage, $c); } $message = join('', @newmessage); print("New message: ", $message, "\n");
Others may know a better way to implement it, and I look forward to seeing their postings. Hope it at least helps.
In reply to Re: Rot13 Source Jumbling
by atcroft
in thread Rot13 Source Jumbling
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |