Colleagues,
In vigenere, I can obtain and error check the required user inputs and I have a conceptual understanding of the steps required to encipher the plaintext with the keyword, looping where necessary.
However, I am struggling to achieve the correct enciphering and at this point have gone somewhat code-blind..
If anyone can take a look at the code and give me a hint as to where I am going wrong it would be much appreciated.
Relevant code:
for (int i = 0, k = 0; i < plaintext_length; i++)
{
if ( isalpha(plaintext[i]) && isupper(plaintext[i]))
{
encrypted_char = ((plaintext[i] - 65) + (keyword[k % keyword_length]) % 26 + 65);
printf("%c", encrypted_char);
k++;
}
else if ( isalpha(plaintext[i]) && islower(plaintext[i]))
{
encrypted_char = ((plaintext[i] - 97) + (keyword[k % keyword_length]) % 26 + 97);
printf("%c", encrypted_char);
k++;
}
else if (isspace(plaintext[i]))
{
printf("%c", encrypted_char);
}
else
{
printf("%c", plaintext[i]);
}
}
Many thanks in advance!
keyword_length
? isn'tkeyword
already an integer? Also why are you considering a special case when it is a space?, space should be the same that all other non alphabetical characters.