I have tried a lot of solutions to print out the cypher text, but it is still not working. Now finally I have managed to successfully print the first 5 letters with the keyword bacon. However, the rest is still not correct. The loop with the keyword is not continued, what am I doing wrong? Do I miss a variable? Or....? Below a part of my code, please let me know if more is needed:
// get input from user
string sentence = GetString();
// check all characters
int keylength = strlen(sentence);
for (int i = 0, k = 0; i < keylength; i++)
{
// if it is a letter, check for the following
if (isalpha(sentence[i]))
{
// if upper case for message and key
if (isupper(sentence[i]) && isupper(key[k]))
{
printf //code to print letter;
}
// if lower case for message and key
else if (islower(sentence[i]) && islower(key[k]))
{
printf //code to print letter;
}
// if upper case for message and lower case for key
else if (isupper(sentence[i]) && islower(key[k]))
{
printf //code to print letter
}
// if lower case for message and upper case for key
else if (islower(sentence[i]) && isupper(key[k]))
{
printf //code to print letter
}
k++;
}
// for other values like numbers and special signs
else
{
printf("%c", sentence[i]);
}
So if I type the sentence: meet me at the park I get the following: Meet me at the park at eleven am Negh z xw zz ini bokwr se
As you can see, the first letters are ok, but after that it makes no sense. What do I not see? How to loop the keyword again to repeat the procedure to cypher the rest of the sentence?