我编写了一个程序,它加密对应于字母的数字并对其进行解密,但是我如何制作它,以便当我要求输入时,我将每个字母分配给它的数字,然后执行操作并打印消息的加密和解密没有几行代码?这是我的程序:
print "Caesar's Cipher\n\n";
print "Reference:\n\n";
print "A B C D E F G H I J K L M\n";
print "0 1 2 3 4 5 6 7 8 9 10 11 12\n\n";
print "N O P Q R S T U V W X Y Z\n";
print "13 14 15 16 17 18 19 20 21 22 23 24 25\n";
print "\nEnter a Message (User numbers separated by space):\n";
$string = <>;
@sarray = split(" ",$string);
foreach $x (@sarray){
if ($x >=0 && $x <= 25){
$x = ($x+3)%26;
} else {
print "Entered incorrect message.\n";
die;
}
}
print "\nEncryption: \n";
print "@sarray\n";
foreach $x (@sarray){
if ($x >=0 && $x <= 25){
$x = ($x-3)%26;
} else {
print "Entered incorrect message.\n";
die;
}
}
print "Decryption: \n";
print "@sarray\n";
我希望能够只输入“HELLO”之类的内容,然后它会加密消息并解密它。