Ascii Vigenere Cipher Not Decrypting Properly
My Vigenere cipher program has all come down to two lists. One a list of ASCII numbers which represent the characters of the message to be encrypted/decrypted and the other is a li
Solution 1:
The problem is in the statement (x - y) % 26
because mod of a number is defined from 0 to m-1, in the above case 0 to 25, but while subtracting you get negative numbers, so in order to get the correct result you should do this (x - y + 26) % 26
. If the negative value we get by (x-y)
is lower than "-m" in the above case lower than -26, then the no still remains negative, then you have to make it positive, here is the pseudo code for that :
val = (x - y) % 26
while(val < 0) val += 26
val = val % 26
Post a Comment for "Ascii Vigenere Cipher Not Decrypting Properly"