描述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
#include
string decrypt(string ciphertext) { string plaintext = ""; for (int i = 0; i < ciphertext.length(); i++) { char c = ciphertext[i]; if (c >= 'A' && c <= 'Z') { int index = c - 'A'; index = (index + 21) % 26; plaintext += 'A' + index; } } return plaintext; }
int main() { string ciphertext; getline(cin, ciphertext); string plaintext = decrypt(ciphertext); cout << plaintext << endl; return 0;
原文地址: http://www.cveoy.top/t/topic/iNtZ 著作权归作者所有。请勿转载和采集!