//Iterate over each character in plaintext(i)
int m = strlen(keyword);
for (int i = 0, j = 0, l = strlen(plain); i < l; i++)
{//Iterate over each character in keyword(j) only if plaintext[i] is alphabetic
if (islower(plain[i]))
{
printf("%c", (((plain[i] = plain[i] - 'a') + (keyword[j]%m) % 26) + 'a'));
j++;
}
else if (isupper(plain[i]))
{
printf("%c", (((plain[i] = plain[i] - 'A') + (keyword[j]%m) % 26) + 'A'));
j++;
}
else
{
printf("%c", plain[i]);
}
}
printf("\n");
return 0;
Hey, hoping someone can give me some advice. My program compiles but doesn't output the correct cyphertext. For example, an input of 'michael' with a key of ABC results in 'nkchcgn. I think the problem is somewhere within the loop but I can't figure out where.
I tried to read some other common loops problems people had with vigenere and I made sure to track the [i]th character over the plaintext separately from the [j]th character of the keyword. I also made sure to increment [j] only if the plaintext received is alphabetic. I'm not very confident with my use of loops and the modulo function, so I would appreciate any advice.
My full code can be found here