Updates

Vigenere Cypher

So I’m trying to convert my Caesar Cypher into a Vigenere Cypher. The difference being that Vig uses a shift word instead of a single shift number. For example:

Caesar Cypher:

– if the shift number is 2, and the secret message is “A B C” then the encrypted message would be, “C D E”. 

Vig Cypher:

– each letter in the shift word has a corresponding number. A = 0, B = 1, C = 2, etc. SO lets say our shift word is “cat”. That would mean our shift sequence is: 2 – 0 – 20. So if our message was “New York”, the encrypted message would be, “Peq Aolm” (pending I counted through my alphabet correctly). The shift sequence of “cat” is repeated until the message is fully encrypted. 

So I cant figure out how to implement a shift word, with its corresponding shift number, and then iterate over a secret message using the proper sequence of numbers. I’m at a loss to figure out how to iterate over an array with another array.

Suggestions?

Advertisements
Standard

One thought on “Vigenere Cypher

  1. The real key is learning how to break down the problem. You’re attacking it word by word. You need to divide the problem into smaller chunks to get it to look like the Caesar cipher problem.

    Just like in the Caesar cipher, you need to iterate over your message letter by letter. The only difference is now, the character to shift by is not constant. So as you iterate over the message, you now also need to iterate over the key string. Something like this:

    for (int i = 0; i < strlen(message); i++)
    {
    int shiftChar = key[i];
    DoTheCipherWork(message[i], shiftChar);
    }

    DoTheCipherWork does the actual shifting and printing on each character – same as in Caesar.

    Now since the key is probably not the same length as your message, you will need to figure out what operator will be appropriate to get the proper index, instead of just using i. Hint – you've already been exposed to it in an earlier task.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s