Hello! Just in case any fellow learners are looking for a discussion/solution thread for:
Steps 1 - 4 should be understandable with the solution key.
As for Step 5, the Vignere Cipher section:
I’ve tried this project twice separate times, and seen 2 different solutions in the Jupyter Notebook posted by Codecademy. The current solution they have posted is much cleaner than the previous one, but it took me some time to understand it fully.
Here’s my notes, I hope it helps you if you should ever feel stumped:
def vignere_decoder(coded_message, keyword): # Part 1 - Creating keyword phrase: keyword_charindx = 0 keyword_phrase = "" # Part 1a & 1b can be interswitched (doesn't matter if you work on the characters/letters in or out of the punctuation list) # Part 1a - Including all punctuations in keyword phrase for i in range(0, len(coded_message)): if coded_message[i] in punctuation: keyword_phrase += coded_message[i] #add it as it is # Part 1b - Skipping punctuations while mapping keyword phrase to coded message else: keyword_phrase += keyword[keyword_charindx] keyword_charindx = (keyword_charindx + 1) % len(keyword) # print(keyword_phrase) # just to check how it looks # Part 2 - Decoding the message decoded_msg = '' # Part 2a - Including all punctuations in decoded message for i in range(0, len(coded_message)): if coded_message[i] in punctuation: decoded_msg += coded_message[i] #add it as it is # Part 2b - Deducing the char index of the decoded char else: decoded_charindx = alphabet.find(coded_message[i]) - alphabet.find(keyword_phrase[i]) decoded_msg += alphabet[decoded_charindx % len(alphabet)] return decoded_msg message = "dfc aruw fsti gr vjtwhr wznj? vmph otis! cbx swv jipreneo uhllj kpi rahjib eg fjdkwkedhmp!" keyword = "friends" print(vignere_decoder(message, keyword)) # prints "you were able to decode this? nice work! you are becoming quite the expert at crytography!"
Hope this helps if anyone is looking! Step 6 can be achievable in similar steps reversed.
I also found an alternate video that might be interesting to watch on the Vignere Cipher on Youtube:
Vigenere Cipher Encryption and Decryption in Python. It uses ASCII characters to build the module, which means that we do not need to create a separate alphabet and punctuation list.