0

I have been stuck on this for over a week. I actually did pset3 in the meantime because I can't figure out what is wrong. It passes all of the checks except 1. When check50 checks against a plaintext string of "hello, world!" with a key of baz it seems to be recognizing the quotes in the plaintext as alpha and iterating the key when it shouldn't. Error message and code below. Thanks in advance for any insight.

:) vigenere.c exists.
:) vigenere.c compiles.
:) encrypts "a" as "a" using "a" as keyword
:) encrypts "barfoo" as "caqgon" using "baz" as keyword
:) encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
:) encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
:) encrypts "world!$?" as "xoqmd!$?" using "baz" as keyword
:( encrypts "hello, world!" as "iekmo, vprke!" using "baz" as keyword
expected "ciphertext: iek...", not "ciphertext: ie..."
:) handles lack of argv[1]
:) handles argc > 2
:) rejects "Hax0r2" as keyword

[hid code]

1
  • Weirdly, when I enter the "hello, world!" string in plaintext in the CS50 IDE with the key as baz I get the output: ~/workspace/pset2/vigenere/ $ ./vigenere baz plaintext: "hello, world!" ciphertext: "hdmln, vprke!" While check 50 gets the output: Actual Output: ciphertext: iekmo, wnslc! Expected Output: ciphertext: iekmo, vprke! – CM23 Mar 12 '18 at 18:08
2

The issue is that you are incrementing the key even if you aren't using it.

For the example:

h e l l o ,   w o r l d !
b a z b a     z b a z b
=========================
i e k m o ,   v p r k e !

And your program does this

h e l l o ,   w o r l d !
b a z b a z b a z b a z b
=========================
i e k m o ,   w n s l c !

Can you see why? You shouldn't increment the key unless you use it. You're incrementing it with the i variable. You need a separate variable to keep track of key usage.

1
  • Thank you. I will try adding another variable. – CM23 Mar 15 '18 at 1:35

You must log in to answer this question.

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