Coded Correspondence: Vigenere Cypher

I’m having some issues trying to figure out what codecademy is asking us to do in this off-platform exercise.

I was able to breeze through steps 1 through 4 without a problem. The explanation pretty clear, However, step 5 isn’t so clear, and of course there is no available solution or video walk-through.

I cannot seem to make sense of the example that codecademy gives, and considering that this updated track has had a number of mistakes in it up to this point, I’m not sure if there are mistakes in the example given by codecademy, or if I’m just not understanding how the Viginere Cypher works.

If they keyword is ‘dog’ and the message is ‘barry is the spy’
replacing ‘barry is the spy’ with ‘dog’:
dogdo gd ogd ogd

How did they get the resulting ‘place values’ (I’m assuming they mean index of a list containing the alphabet here?):
4 14 15 12 16 24 11 21 25 22 22 17 5

If ‘place value’ is the same as ‘index’, then in a list of the alphabet d should be 3, o would be correct at 14, but I have no clue how they got 15 for g or any of the other 'place values’.

Does anyone know what a ‘place value’ is? Do they mean ‘index’ of an alphabet list? How did codecademy get these ‘place values’?

Below are the instructions and example given by codecademy:

Salutations! As you can see, technology has made brute forcing simple ciphers like the Caesar Cipher extremely easy, and us crypto-enthusiasts have had to get more creative and use more complicated ciphers. This next cipher I'm going to teach you is the Vigenère Cipher, invented by an Italian cryptologist named Giovan Battista Bellaso (cool name eh?) in the 16th century, but named after another cryptologist from the 16th century, Blaise de Vigenère.

The Vigenère Cipher is a polyalphabetic substitution cipher, as opposed to the Caesar Cipher which was a monoalphabetic substitution cipher. What this means is that opposed to having a single shift that is applied to every letter, the Vigenère Cipher has a different shift for each individual letter. The value of the shift for each letter is determined by a given keyword.

Consider the message:

barry is the spy

If we want to code this message, first we choose a keyword. For this example, we’ll use the keyword

dog

Now we repeat the keyword over and over to generate a _keyword phrase_ that is the same length as the message we want to code. So if we want to code the message "barry is the spy" our _keyword phrase_ is "dogdo gd ogd ogd". Now we are ready to start coding our message. We shift each letter of our message by the place value of the corresponding letter in the keyword phrase, assuming that "a" has a place value of 0, "b" has a place value of 1, and so forth. Remember, we zero-index because this is Python we're talking about!

          message:     b  a  r  r  y    i  s   t  h  e   s  p  y

   keyword phrase:     d  o  g  d  o    g  d   o  g  d   o  g  d

resulting place value: 4 14 15 12 16 24 11 21 25 22 22 17 5

So we shift "b", which has an index of 1, by the index of "d", which is 3. This gives us an place value of 4, which is "e". Then continue the trend: we shift "a" by the place value of "o", 14, and get "o" again, we shift "r" by the place value of "g", 15, and get "x", shift the next "r" by 12 places and "u", and so forth. Once we complete all the shifts we end up with our coded message:

eoxum ov hnh gvb

As you can imagine, this is a lot harder to crack without knowing the keyword! So now comes the hard part. I'll give you a message and the keyword, and you'll see if you can figure out how to crack it! Ready? Okay here's my message:

dfc aruw fsti gr vjtwhr wznj? vmph otis! cbx swv jipreneo uhllj kpi rahjib eg fjdkwkedhmp!

and the keyword to decode my message is

friends

Because that’s what we are! Good luck friend!

Any and all help would be greatly appreciated. I’m really disliking the disorganized and seemingly ‘rushed’ manner of these course updates.

1 Like

Hi,
You’re assumption is correct. Where before you had one consistent value for how much to offset each character, this time it changes letter to letter.
The value of the keyword is the index of those letters in a string of the alphabet. So, a= 0, b= 1, c= 2, etc.
So dog works out as [3, 14, 6] and so we use those values repeatedly when going through the message;
The first letter is offset by 3
The second by 14
The third by 6
Then we repeat and the fourth is offset by 3 again,
etc.

So, for the final message you have to first work out the value for each of the letters in friends. Then use those values to decode the message.
(Remember to ignore spaces and punctuation)

Hope that helps

I understand that. What I’m not understanding is the CodeCademy instructions.

                      message:       b  a  r  r  y    i  s   t  h  e   s  p  y

         keyword phrase:       d  o  g  d  o    g  d   o  g  d   o  g  d

Got this part. Easy.

resulting place value: 4 14 15 12 16 24 11 21 25 22 22 17 5

Wait, what? Let’s see CodeCademy’s explanation:

    So we shift "b", which has an index of 1, by the index of "d", which is 3. This gives us an place value of 4, which is "e". Then continue the trend: we shift "a" by the place value of "o", 14, and get "o" again, we shift "r" by the place value of "g", 15, and get "x", shift the next "r" by 12 places and "u", and so forth.

Okay, so we shift the index of “b” (1) by the index of “d” (3), which gives us “e” (4). 3+1=4. Got it.
We shift the index of “a” (0) by the index of “o” (14), which gives us “o” (14). 0+14=14. Got it.

What I’m not getting is how CodeCademy got the next values. According to CodeCademy:

we shift “r” by the place value of “g”, 15, and get “x”

The index of “r” is 17 and the index of “g” is 6, which gets “x” at index 23. We’ll assume that CodeCademy had a typo or a brainfart, otherwise I’m not sure why they threw in that 15.

Moving along.

According to CodeCademy:

shift the next “r” by 12 places and “u”

So we shift the index of “r” (17) by “d” (3) and get “u” at index 20. Not sure where they got the 12 or the rest of those values (15 12 16 24 11 21 25 22 22 17 5). Where did CodeCademy pull those numbers from, as they don’t result from shifting message[i] by keyword_phrase[i].

Is this a mistake by CodeCademy, or am I missing something? It’s incredibly frustrating as there have been a lot of these mistakes throughout the entire course (I’m 82% through the Data Science track) so identifying what is a CodeCademy mistake versus simply misunderstanding the instructions is becoming painfully difficult, especially because I’m trying to break each problem down piece by piece to solve them, instead of cheating by looking at the solution (which may or may not be faulty as well).

If my logic is correct, then CodeCademy’s example is incorrect (and utterly confusing), unless I’m missing something fundamental.

1 Like

That does sound odd. Have you checked again, because I’ve got different values - maybe they spotted the mistake at some point and edited it.
I have;
place values of 24, 12, 11, 14, 10, 2, 15, 5, 1, 1, 4, 9, 21
i.e
b-d, a-o, r-g
so the coded message is;

ymlok cp fbb ejv (rather than: eoxum ov hnh gvb)

and the friends message is;

txm srom vkda gl lzlgzr qpdb? fepb ejac! ubr imn tapludwy mhfbz cza ruxzal wg zztcgcexxch!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.