到目前为止,我有这个凯撒密码程序
#include <iostream>
using namespace std;
string encryptText(string plaintext, int rshift)
{
string t;
for (int i=0;i<plaintext.length();i++)
{
if (islower(plaintext[i]))
t += char(int(plaintext[i]+rshift-97)%26 +97);
else if (isupper(plaintext[i]))
t += char(int(plaintext[i]+rshift-65)%26 +65);
else
t;
}
return t;
}
int main()
{
string plaintext, t;
int rshift;
cout << "enter the plaintext\n";
getline (cin,plaintext);
cout << "enter the right shift number\n";
cin >> rshift;
cout << encryptText (plaintext, rshift)<< endl;
}
的问题是,我的程序不包括从用户输入(明文)的空间。此外,它还包括特殊的文字记录器。例如,如果我输入
Hello World!
与10右移,我应该得到
Rovvy Gybvn!
而是我得到
RovvyGybvn
“*我应该得到Rovvy Gybvn !. bu而不是我得到Rovvy Gybvn!*” - ? – Fureeish
'else t;'什么都不做。 – 2017-10-16 19:54:21
无关:使用'rshift-'a''而不是'rshift-97'。 1.更容易推断意图。 2.它可以移植到更多种类的字符集中。 – user4581301