Coded Correspondence

I have just got this project myself and am just completely stuck with it. It says we should use the python skills we have learned to finish this project, but, after reading the questions I feel like I haven’t learned ANY of the skills necessary to finish this project.

Did anybody else feel like that with this project?

1 Like

This project is a really common starter project. In fact, it appears in many of the different program language courses on Codecademy (I’ve completed it in the Python course for Computer Science and in C# standalone course).

What skill do you feel like you are missing?
How are you feeling stuck or lost?

Thank you for the reply! Honestly, I read the question and dont even know where to begin haha. My only thought is to have some sort of for loop checking a letter and then - on an index. I feel that the jump between projects here is quite large, or maybe im just having a bad day haha.

So start with the simpler version of a Caesar cipher. The Vigenere cipher adds a few extra steps, but all of them are things that you learn how to do in the Caesar cipher. Let’s say you have the world “Hello” and you want to shift each letter forward by 1 letter. The process is pretty simple:

Step 1: Loop through each of the letters. We want to move each letter forward, so we have to go through the string and look at each letter one at a time. There are several ways you can do this, including using a loop that goes through each index of the string, or using a loop that just goes through each letter.

Remember to transfer your message to all lowercase before looping through. This is taught in the strings lesson.

Step 2: Okay, so imagine we’re looping through each letter. Now, we need to solve which letter in the alphabet we’re looking at. So in our example, we’re on the letter “h” in the word “hello”. How would you count irl where letter “h” is in the alphabet? Probably another loop where you raise a finger for each letter, right? (ie A = 0, B = 1, C = 2, etc etc. And yes, A = 0 because the first index in a string is 0)

Well that’ super easy to do! Write all the letters out on a string variable before your first loop (we don’t want to make this string each time, so instead we’ll hold it in the computers memory as a variable for now). You can now loop through each letter of your new string until you find the index that matches the current letter (This is the basic way of running the loop, but there’s an even better way in the hint).

Hint: Look back in the strings lesson and see if there’s an easy python code for finding the first index of a letter in a string. You can now search the alphabet string for the letter we’re looking for and it returns the alphabet’s index.

Step 3. Okay so we have our letter’s index. For the letter “h”, that index is 7. However, we’re trying to move it to a different index (which in this case, we are trying to increase by 1 letter, or move it to “i”, that index is 8. Well, just add the offset to the index number, and then look through your alphabet string for the new offsetted index. For instance, alphabet[7] = “h”, so alphabet[8] = “I”.

Hint 1: During this step, think about what happens when you add an index to a number greater than 26 (the number of letters in the alphabet). If we want to move the “y” character by 3 values, then we’d hit a problem because we’d be out of alphabet. So your loop will need to take that into account. I recommend looking into the modulo “%” function for this, as it’s so much easier than most other options.

Hint 2: Until you figure out how to handle symbols, it might be smart to just exclude them. IE if you add a symbol to your secret message, you can either pass it directly to the string variable mentioned in the next part, or you can skip adding it to the output string for now.

Step 4. In a new string variable, add the offset letter to the string. You’ll have to declare this string variable before the first loop, because we want to add 1 letter for each letter in the first loop. Now we just have to complete all the loops and ta-da, the string will be “coded”.

Basically, you are putting your skills of variables, computer math, computer strings, loops, and if statements all together to write this code. It’s also the foundation for computer security engineering, which is kinda cool to learn.

1 Like

I feel the same. It’s hard to do these projects when you don’t perfectly command those skills