I have been working on vigenere for a long time now, and here is my issue. plaintext cab with a keyword of ab returns ccbbbb. so, the plaintext is enciphering correctly but the last letter is repeating for as long as the plaintext? My only ideas as to why this is, is that either I am treating j (position in keyword) incorrectly, or my condition for looping through the plaintext is wrong. I have thoroughly checked both, but cannot seem to see the problem. Will post some of my code below. Any pointers in the right direction would be amazing, thank you thank you in advance.
// execute loop for every char of the plaintext
for (int i = 0, j = 0; i<plen; i++, j++)
{
// execute if char is alphabetical
if (isalpha (p[i]))
{
// key wraparound
if (j >= keylen)
j = 0;
// encryption if char of plaintext and char of key are uppercase
if (isupper (p[i]) && isupper (keyword[j]))
{
// code here rotates plain char by key char and prints
}
// encription if char of plaintext and char of key are lowercase
else if (islower (p[i]) && islower (keyword[j]))
{
// code here rotates plain char by key char and prints
}
// encryption if plaintext char is uppercase and keyword char is lowercase
else if (isupper (p[i]) && islower (keyword[j]))
{
// code here rotates plain char by key char and prints
}
// encryption if plaintext char is lowercase and keyword char is uppercase
else if (islower (p[i]) && isupper (keyword[j]));
{
// code here rotates plain char by key char and prints
}
}
// prints non-alphabetical plaintext char
else
{
j = j - 1;
printf("%c", p[i]);
}
}