First, you should consider ciphering uppercase characters too!
Second, the formula assumes that each of your alphabetical characters has a value in [0, 25].
For example, when ciphering, the letter A
should be equivalent to 0
, the letter B
should be equivalent to 1
... Z
should be equivalent to 25
.
Similarly, a
should be equivalent to 0
, b
should be equivalent to 1
... z
should be equivalent to 25
.
At the same time, after ciphering, each character should have its original ASCII value back.
For example, if the original char
was ciphered to A
(i.e., 0
), it should become 65
. If, rather, it was ciphered to B
(i.e., 1
), it should become 66
and so on.
Same thing applies for lowercase char
s.
Third, the ciphering formula per the pset specification page is
c = (p + k) % 26
Where c
is the ciphered char
, p
is the current plain char
in [0, 25] and k
is the current key. And since k
must be an alphabetical char
, it has to be in [0, 25] either.
What you're doing wrong is
You're never getting the value of your plain char
(i.e., current
) to be in [0, 25].
You're not considering uppercase char
s either in the plaintext or in the keyword.
You're adding 97
to current at the end without subtracting 97
from it at the first place.