I have been trying to troubleshoot my vigenere code for a little bit tonight. My psuedocode makes sense, but translating it to the code:

  1. code works if I use lower case and no spaces
  2. cipher does not work if I use upper case letters -it does not cipher the right amount of letter spaces for the key.
  3. When I add spaces and/ or non-alpha characters the loop still thinks this space is a valid space and does not skip it... I print the non alpha or space accurately, but it throws cipher off by the same amount of those spaces..

see a portion of code below. I know I should be freezing key for items in #3.. thought I was doing that. For the upper case, a little lost. .

Help -Thanks![]1

1 Answer 1


For starters, your code assumes that both the key and the letter to be encoded are the same case. There is no correlation between them. Either can be upper or lower case at any time. In other words, your code doesn't handle the key being upper case and the text being lower case or vice versa.

Next, you index through both the text and the key using the same value. If the plain text character is not an alpha, such as a number, space, or punctuation, it is just reprinted without being encoded, so the key should NOT be indexed. That means that you need to have separate values to track the indexing through both the key and the plain text.

That should get you started, no guarantees there aren't other issues buried in the code.

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

  • Thanks!! I have that in my psuedo code, but I am still struggling to make this happen. I am trying to figure out your first thought, but actually made the code worse. I also cannt figure out the index.. still trying.. thanks thought, your comments really helped!! Commented Sep 3, 2015 at 2:08

You must log in to answer this question.

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