in reply to Alpha-search, by letter.
Fixed up, your code would be
oruse strict; use warnings; my $rot = 6; chomp(my $message = lc(<>)); $message =~ s/([a-z])/ chr( ( ord($1) - ord('a') + $rot + 26 ) % 26 + ord('a') ) /ge; print("$message\n");
or for repeated useuse strict; use warnings; my $rot = 6; my $src = join '', 'a'..'z'; my $dst = substr($src, $rot) . substr($src, 0, $rot); chomp(my $message = lc(<>)); eval "\$message =~ tr/$src/$dst/;"; print("$message\n");
use strict; use warnings; my $rot = 6; my $src = join '', 'a'..'z'; my $dst = substr($src, $rot) . substr($src, 0, $rot); my $tr = eval "sub { local \$_ = \@_ ? \$_[0] : \$_; tr/$src/$dst/; return \$_; }"; chomp(my $message = lc(<>)); $message = $tr->($message); print("$message\n");
Set $rot to -6 to "decrypt".
This method of encrpytion is particularly bad because
|
|---|