0

I'm sure I'm doing something dumb, but after spending hours searching the topic, I can't figure it out. Instead of pairing the 1st char in the keyword to the 1st char in the plaintext, the 2nd char in the keyword to the 2nd char in the plaintext... the ith char in the keyword to the ith char in the plaintext, my code applies all chars in the keyword to the 1st char in the plaintext, the all chars in the keyword to 2nd char in the plaintext, etc. For example:

$ ./vigenere aba
plaintext: aaaa
ciphertext: aaaabbbbaaaa

I'm sure this is a case of it doing what I told it to instead of what I meant for it to, but I can't figure out where I am going wrong. Any help would be much appreciated. I think I've posted the relevant portion of the code

code removed in keeping with course's policy on academic honesty 
0

You've essentially answered your own question. It's applying the entire key to each character in the plaintext. In other words, it's executing a for loop inside a for loop, i.e., a pair of nested for loops.

Why?

Why does the code loop across the key at all?

Yes, it needs to loop across the plaintext, but only one char from the key is consumed as each letter in the plaintext is processed, and none when a non-alpha is processed. Doesn't that say that a for loop should NOT be used to process the key? Maybe just keep track of which letter in the key is next to be used?

This should get you started. ;-)

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

You must log in to answer this question.

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