Run ID:73980

提交时间:2024-05-20 21:23:15

#include <iostream> #include <string> using namespace std; string encrypt(string plaintext) { string encryptedText = ""; for (int i = 0; i < plaintext.length(); i++) { char c = plaintext[i]; if (isalpha(c)) { // 循环左移3个位置 c = (c - 'a' + 23) % 26 + 'a'; } encryptedText += c; } // 逆序存储 int left = 0, right = encryptedText.length() - 1; while (left < right) { swap(encryptedText[left], encryptedText[right]); left++; right--; } return encryptedText; } int main() { string plaintext; cout << "输入明文字符串:"; getline(cin, plaintext); string ciphertext = encrypt(plaintext); cout << "加密后的密文字符串:" << ciphertext << endl; return 0; }