我创建了一个程序,它采用一个“单词”和一个 num 参数作为移位数。例如,如果字符串是Caesar Cipher
并且 num 是 2,则输出应该是Ecguct Ekrjgt
。但我希望标点符号、空格和大小写保持不变。我也不能添加一个句子。一句话。我不允许使用字符串。
#include<iostream>
using namespace std;
int main()
{
char name[50] = { '\0' };
int cipherKey, len;
cout << "Enter cipher key: ";
cin >> cipherKey;
cout << "Enter a message to encrypt: ";
cin >> name;
len = strlen(name); // this code just inputs the length of a word. after spaces it won't calculate.
for (int i = 0; i < len; i++)
{
char temp = name[i] + cipherKey;
cout << temp;
}
cout << "\n\n";
return 0;
}