There are two problems in the code.
First is the treatment of upper case letters in the keyword. Note that in one case, the code subtracts a
from keyC, and in the other A
is subtracted. But that's based on the case of the plain text character. That subtraction needs to be based on the case of the letter in the keyword.
Second, the code advances to the next character in the keyword for every character in the plain text. The "correct result" doesn't advance to the next character of the keyword if the plain text character is a space
character.
Here's an example of what I'm talking about for the second problem
text Meet me at
keyC baco nb ac
i 0123456789 i must always increment to the next char in plain text
k 0123 40 12 index into the keyword does not increment on non-alpha
Therefore k
cannot be computed directly from i
with the line
keyWordWrapper = i % strlen(keyWord);
Instead k
needs to be initialized to 0
and then incremented only when the plain text contains an alpha character. The following line will compute the correct index into the keyword.
keyWordWrapper = k % strlen(keyWord);
The only difference is that i
is replaced by k
and k
only increments when the plain text has an alpha character.