I can not seem to figure out why only certain letters in my decryption are not working. I am trying to decrypt the letters kddkmu with a key of 10. It is suppose to come out to attack but every time I run the code it comes out to aZZack. I believe the problem has something to do with my modulus operation but no matter what I do I cant figure out the problem.
int key = 10;
ciphertext = "kddkmu";
plaintext = shift_decrypt(ciphertext, key);
cout << "2. Decryption of the ciphertext: " << ciphertext << endl;
cout << " Key: " << key << endl;
cout << " Plaintext; " << plaintext << endl << endl;
with
string shift_decrypt(string p, int a)
{
string dtext = "";
for (int i = 0; i < p.length(); i++)
{
dtext += char(int(p[i] - a - 97) % 26 + 97);
}
return dtext;
}
I am not getting any errors its just decrypting the dd as ZZ for some odd reason