I am trying to fix my code for vigenere cipher. I guess there is something wrong with my if (isupper) and if else (islower) loops. I can't figure out what. First I was using two nested for loops but that was causing me trouble. So I changed my code, but still my code is not giving the expected answer. I hope someone can help me!
for(int i = 0, n = strlen(message); i < n; i++)
{
char cipher[i];
int kwlength = strlen(keyword);
int countkey = 0;
if (isalpha(message[i]))
{
int keyindex = 0;
keyindex = (countkey % kwlength);
// Checking lower case alphabetics.
if (islower(message[i]))
{
cipher[i] = ((message[i] - 'a') + (keyword[keyindex] - 'a')) % 26 + 'a';
printf("%c", cipher[i]);
}
// Checking upper case alphabetics.
else if (isupper(message[i]))
{
cipher[i] = ((message[i] - 'A') + (keyword[keyindex] - 'A')) % 26 + 'A';
printf("%c", cipher[i]);
}
countkey++;
}
}