0

This is my first time posting on here so bare with me. Having a little trouble with pset2 vigenere.c. I've been looking through the forums looking at all the questions pertaining to my question, but can not come up with anything. I have 4 "else if" statements to check if message[i] and key[j] are either lower or upper, but the out put comes out as "CaQGoh". At a complete loss on what the problem is. Below is my else if statements and thank you in advance for any input/help!

     if (islower(message[i]) | islower(key[j]))
     {
        letter = message[i] - 97;
        keyletter = key[j % keylength] - 97;
        ciphertext = ((letter + keyletter) % 26) + 97;
        j++;
     }
     else if (isupper(message[i]) | isupper(key[j]))
     {
         letter = message[i] - 65;
         keyletter = key[j % keylength] - 65;
         ciphertext = ((letter + keyletter) % 26) + 65;
         j++;
     }
     else if (isupper(message[i]) | islower(key[j]))
     {
         letter = message[i] - 65;
         keyletter = key[j % keylength] - 97;
         ciphertext = ((letter + keyletter) % 26) + 65;
         j++;
     }
     else
     {
         letter = message[i] - 97;
         keyletter = key[j % keylength] - 65;
         ciphertext = ((letter + keyletter) % 26) + 97;
         j++;
     }

I have also tried doing &&'s and the out put comes out as "CaQaun". Again any input will help greatly appreciated. Thank you again.

0

I see two issues. First, your if and else if tests all use the | operator, a bitwise operator. Instead, the appropriate operators would be the 'and' operator, && or the 'or' operator ||. (I'm not saying which though. ;-) )

Second, without seeing the rest of the code related to j, it's hard to know, but I suspect that another problem lies in the fact that you are testing for key[j] and not key[j % keylength]. If you are testing for key[j] without j being reset to 0 when it equals keylength, it's testing whatever is stored after the key array, possibly message itself.

This should get you going. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thank you for the help I am at work right now, but a quick glance this morning at my code, I am missing the j to keylength condition. Will look into it when I get home. I initialized j and keylength in my for loop with i. So I'm guessing I need a second for loop to have my condition. Thank you again for the help!!!! – John Sobie May 19 '16 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .