Off-Platform Project: Coded Correspondence

https://www.codecademy.com/courses/learn-python-3/informationals/python3-coded-communication

In this project this is what is given:

Now we use the 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 the 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

So in this code:

message = “dfc aruw fsti gr vjtwhr wznj? vmph otis! cbx swv jipreneo uhllj kpi rahjib eg fjdkwkedhmp!”
keyword = “friends”

d = index 3
f = index 5

so index is at 8 which in the alphabet is “i”

but the answer is “y”

here is the full sentence answer:
you were able to decode this? nice work! you are becoming quite the expert at crytography!

how did they get y from index 8 in the alphabet?

This is what is written directly in the problem:

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".

We are adding the 2 index places together. How in the world do you get “y” by adding index places “f” and “d”

To get ‘y’, it would appear that the index was shifted to the left instead of to the right.

>>> 3-5
-2
>>> 'abcdefghijklmnopqrstuvwxyz'[-2]
'y'
>>>
1 Like

Is the prompt wrong? Or is my English understanding wrong?

The prompt seems to be asking to add them together, not subtract.

my solution, you can call eather functions at the end to test the coder an decoder

off-platform-project-coded-correspondence.txt (1.1 KB)

2 Likes

Very interesting and challenging project.
My solution is here as a jupyter notebook or python code.

Github project

2 Likes

Hi! I have a question about this project. I am trying to understand why index = (index + 1) % len(keyword) works for making the keyword phrase for the Vigenere Cipher instead of just index += 1. Can anyone help me understand? Thanks!

In the ‘dog’ example shown, they are adding the indexes together to encode a message. To decode an encoded message, you need to subtract the indexes.

I found this confusing at first too. And their example with the ‘dog’ encoding doesn’t make much sense. Only the first 2 “resulting place values” shown add correctly, the others in the list seem like garbage to me. If ‘b’ at index 1 plus ‘d’ at index 3 makes 4, then why does ‘r’ at index 17 plus ‘g’ at index 6 make 15, when 17 + 6 is 23. The encoded message uses the letter ‘x’ which is at index 23.

Anyhow, hope this helps!

4 Likes

So if the keyword is ‘friends’, then it’s length is 7 letters long. If you just kept upping the index with ‘index += 1’ then you will surpass the length of the keyword after 7 iterations. Using the mod (%) operator gives you the remainder of the division, which keeps the result in the range of 0-6.

I don’t see this in the solution code, so I am only guessing here. I did it in a different way myself.

This is my solution to this project.

1 Like

Hi there! I’ve just finished this project.
Came across with the same problem you had mentioned and lost a few hours figuring out that the task (prompt) itself was wrong!
This is the first time Codecademy broke me down(

1 Like

Wait, so the given “resulting place values” after the first two examples are wrong?! My god I wasted an hour trying to figure out how ‘r’ index and ‘g’ index equals index 15. :rage:
I should have looked at the coded message first.

1 Like

I literally just wasted a bunch of time on this too… not great when the example explanation has five out of seven figures calculated incorrectly!

1 Like

They should fix it! I remember I reported it, I guess they haven’t.

can pls explain the theory, the dog example is wrong

Hello there,

I was doing this exercise and I got confused about something.

I mean in the explanation text in the beggining it says that the letters have an offset of 3, so the letter index should be -3 from the alphabet’s index.

"
For example, if I chose an offset of 3 and a message of “hello”, I would code my message by shifting each letter 3 places to the left (with respect to the alphabet). So “h” becomes “e”, “e” becomes, “b”, “l” becomes “i”, and “o” becomes “l”.
"

But then the response to the exercise is of decoding an offset of 10 is in fact adding +10 to alphabet’s index.

Did I miss something?

Tx in advance

I don’t think you missed anything, I remember getting caught out on this well. I think the instruction are just a little lacking since offset could arguably be in either positive or negative direction (which is doubly confusing since the example is the opposite to what you require). So long as you found an offset that works for the decoding then all is well.

Hi tgrtim, Actually I was continuing the exercise and understood better my doubt: it is -10 to code a message, but +10 to decode the message. That’s it!
Thanks for the reply and happy coding :slight_smile:

1 Like