I'm at my wits end with this pset2 exercise. When I test my code I get a single error:
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword \ expected output, but not "CaQGoh\n"
Why in the name of all that is holy would my code work for everything else but this one combination? Fuh realz.
Here's what I got:
int y = 0;
// encipher text
for (int i = 0; i < strlen(phrase); i++) {
// exclude non-alpha && blank space values
if ((isalpha(phrase[i])) && (phrase[i] != ' ')) {
// encode uppercase letters
if (isupper(phrase[i])) {
int upper = (((phrase[i] - 'A') + (keyword[y] - 'A')) % 26) + 'A';
printf("%c", upper);
}
// encode lowercase letters
else if (islower(phrase[i])) {
int lower = (((phrase[i] - 'a') + (keyword[y] - 'a')) % 26) + 'a';
printf("%c", lower);
}
// increment or reset keyword character index based on length of keyword - 1
if (y < (strlen(keyword) - 1)) { y++; } else { y = 0; }
}
// otherwise, copy existing character, no adjustment
else {
printf("%c", phrase[i]);
}
}
What gives? Learn me! I am an empty vessel, ready to be schooled in the ways of debuggery!