I'm almost finished with the ´vigenereproblem set incs50` but have one problem my brain can't find the solutions for, anyone have any ideas?

check50 2015.fall.pset2.vigenere vigenere.c:
:) vigenere.c exists
:) vigenere.c compiles
:) encrypts "a" as "a" using "a" as keyword

**:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
\ expected output, but not "xoqmd, szz gflkp!\n"**
:) encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
:) encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
:) handles lack of argv[1]
:) handles argc > 2

It appears you are "consuming" a char in the key when you encounter a non-alpha character in the message, even though you (correctly) do not change the value of the char in the message. That explains why only "say" is encrypted incorrectly.

  • Thanks for answering. I am aware of this but I don't understand why since there is isalpha function in the loop. – lkoks Jun 16 '16 at 15:16
  • Let's say you are using j to cycle through the key one character at a time. It looks like you are incrementing j when isalpha() is false. From the spec: if your code is about to apply the jth character of k to the ith character of p,but the latter proves to be a non-alphabetical character, you must wait to apply that jth character ofk to the next alphabetical character in p; you must not yet advance to the next character in k. – DinoCoderSaurus Jun 16 '16 at 16:51
  • Now it works! Thanks for help:) – lkoks Jun 17 '16 at 9:11

You must log in to answer this question.

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