0

My vigenere cypher mostly seems to work, except that it shifts a character on each iteration for example (I typed "BARFOO" a lot to show the pattern)

dovidm@ide50:~/workspace/pset2 $ ./vigenere BAZ
BARFOOBARFOOBARFOOBARFOOBARFOO
CAQEONCAQGPNCARGONCBSA/H=<KA/H

I also don't see how it gets to the non-alpha characters, since using same method as my (successful) Caesar cypher.

My code is at http://pastebin.com/4aGz5PEd (only look if already completed the pset)

1 Answer 1

1

Hmmm, deja vu. The previous question on this forum had the exact same problem.

The problem is that you are testing for key[ j ] and not key[ j % keylength ]. When j is not reset to 0 after it reaches the length of the key, key[j] will access whatever data is stored sequentially in memory following the key array. This is corrupting the results.

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

3
  • I believe I am already doing that (line 46 of code). Am I doing it incorrectly?
    – David M
    Commented May 19, 2016 at 1:42
  • Line 46 is how you should do it, but look at lines 43 and 51. Those are the lines where you are doing the tests, not 46.
    – Cliff B
    Commented May 19, 2016 at 1:53
  • Oh, thanks! Didn't realize I needed it there as well
    – David M
    Commented May 19, 2016 at 2:10

You must log in to answer this question.

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