what's up? I'm having an issue debugging this code. So for I have been working on Vigenere 2 days (-school time) and works great except for keywords with capitalized letters like BaZ, BAR...
I'm guessing the answer lies on * char c = key[p] < 26 ? key[p] - 'A' : key[p] - 'a'; * because my- Vigenere.c encrypts correctly other combinations of and plaintext but not when it comes to the CAPS of the keyword.
Let me know if you have an idea on how to fix this
/// Rotation of words according to <keyword>
for(int i = 0, j = 0, length = strlen(key), n = strlen(text); i < n ;i++, j++)
{
int p = j % length; // OUTSIDE: To be modified for (else)
if ('a' <= text[i] && text[i] <= 'z')
{
char c = key[p] < 26 ? key[p] - 'A' : key[p] - 'a'; // INSIDE: To reduce processes in case text[i] it's a character.
c = 'a' + (text[i] - 'a' + c) % 26;
printf("%c", c);
}
else if ('A' <= text[i] && text[i] <= 'Z')
{
char c = key[p] < 26 ? key[p] - 'A' : key[p] - 'a'; // INSIDE: To reduce processes in case text[i] it's a character.
c = 'A' + (text[i] - 'A' + c) % 26;
printf("%c", c);
}
else
{
printf("%c", text[i]);
j--;
}
}
printf("\n");
return 0;
https://sandbox.cs50.net/checks/55155b17520345ffaddc580e7fa776c8