描述Julius Caesar曾经使用过一种很简单的密码。对于明文中的每个字符将它用它字母表中后5位对应的字符来代替这样就得到了密文。比如字符A用F来代替。如下是密文和明文中字符的对应关系。密文:A B C D E F G H I J K L M N O P Q R S T U V W X Y Z明文:V W X Y Z A B C D E F G H I J K L M N O P Q R S
#include
int main() { string ciphertext; getline(cin, ciphertext);
for (int i = 0; i < ciphertext.length(); i++) {
if (ciphertext[i] >= 'A' && ciphertext[i] <= 'Z') {
char decrypted = ciphertext[i] - 5;
if (decrypted < 'A') {
decrypted += 26;
}
cout << decrypted;
} else {
cout << ciphertext[i];
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/i23T 著作权归作者所有。请勿转载和采集!