Ceaser密碼不考慮加密中的數字。如何擴展它,以便用字母和數字替換每個字母,然後用XOR每個字符加上一個加密密鑰。這是我到目前爲止編寫的加密代碼...我可以知道我的錯在哪裏....輸出不準確。Ceaser密碼的擴展
string Encrypt (string s)
{
string cipher = s;
int size = s.length();
for(int i = 0; i < size ; i++)
{
if(isalpha(cipher[i]))
{
int x = static_cast<int>(cipher[i]) ; //changing to ascii code
if ((x >= 88 && x <= 90) || (x >= 120 && x <= 122))
x = x - 23;
else
x = x + 3;
cipher[i] = static_cast<char>(x); //changing back to ascii char
cipher[i] ^= 5; // XOR with 5
}
else if(isdigit(cipher[i]))
{
int x = static_cast<int>(cipher[i]) ;
cout << x ;
if (x >= 55 && x <= 57)
x = x - 7;
else
x = x + 3;
cipher[i] = static_cast<char>(x);
cipher[i] ^= 5;
}
}
return cipher ;
}
你所描述的不再是凱撒密碼,所以它的實現完全取決於你。 – duskwuff
有很多人已經解決了這個任務。您是否嘗試尋找他們的解決方案,例如通過做一個簡單的搜索? –