1

I've worked on (and dreamed about) Vigenere for a few days now, and I'm almost there. I think! If I try out my code separately for lower and uppercase letters (by commenting out the irrelevant part), it works fine. But together, I get the wrong kind of gibberish.

Check50 throws these errors:

:( encrypts "a" as "a" using "a" as keyword

\ expected output, but not "T:\n"

:( encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword

   \ expected output, but not "Q7H.JJ`,W=, KKU;R8 Z@Y?_+^DI/!\n"

:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword

   \ expected output, but not "CT:QGH.nT\n"

:) encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword

Note that uppercase seems to work, but not lowercase. (If I comment out uppercase, lowercase works.)

Here's the essentials of my code, in pseudocode:

- loop over string key 

-- is not alpha? return 1.

-- is alpha? 

--- is lower? convert key to numbers so that a == 0

--- is upper? convert key to numbers so that A == 0


- loop over string plaintext 

-- is alpha?

--- is lower? encrypt, increase key counter

--- is upper? encrypt, increase key counter

-- print %c

-- is not alpha? don't encrypt, print %c, don't increase key counter

I'd be grateful for any ideas.

1 Answer 1

1

Looking at what's wrong, all of your values are off by a multiple of 13. Are you using a modulo somewhere? and you are also printing more than one char for every lowercase plain char.

a becomes T: with a key of a   97 -> 84 -> 58
                                 -13   -26

for another one:

w becomes Q7 with a key of b   119 -> 81 -> 55
                                  -38    -26

o becomes H. with a key of a   111 -> 72 -> 46
                                  -39    -26

r becomes JJ` with a key of z  114 -> 74 -> 74 -> 96
                                   -40   -0    

Put in a printf to print your key array to make sure that is correct.

If you run with a key of "baz" then your int array should be {1,0,25} Is it?

Then, put in a printf on each of your ciphers, something like:

printf("ciphering %c with key %d\n", plaintext[i], key[j]);

or whatever you've called them.

Do you see where it might be going wrong?

2
  • 1
    thanks for your fast reply. I've moved my print %c, so it doesn't print twice anymore. The rest of the problem was solved, when I was pointed to two else; statements that should have been else if without ;. Code works now!
    – cor_swe
    Commented Aug 3, 2014 at 9:08
  • Glad to have helped. -Brenda.
    – curiouskiwi
    Commented Aug 3, 2014 at 9:10

You must log in to answer this question.

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