When using a key to decrypt, i was told to use the modulo operator to “wrap around” the alphabet.
I understand how and why this works but i can’t say the same for the decryption process.
//decrypt char pos = encryptedMessage[i]; int alphabetPos = Array.IndexOf(alphabet, decryptedMessage[i]); int newLetterPos = (alphabetPos - key) % 26; char decryptedChar = alphabet[newLetterPos]; decryptedMessage[i] = decryptedChar;
This obviously gets me an index out of bounds.
I get why this doesn’t work the same way as with adding the key.
But i can’t get to a solution for the life of me.
I would appreciate a little pointer!