Off-Platform Project: Coded Correspondence

Hi everyone!

I’m excited to share that I’ve completed the toughest off-platform project in the Data Scientist path. It was a journey full of hard work and dedication, but it feels great to have finished it!

This is my first time posting on the Codecademy forums - a big step for me. Looking forward to hearing your thoughts and constructive feedback!

And if you need my help, feel free to message me.

#Step 1: message = "xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!" ascii_number = 0 shift_number = 0 decode_char = "" decoded_message = "" for i in message: if i.isalpha(): ascii_number = ord(i) - ord("a") shift_number = (ascii_number + 10) % 26 decode_char = chr(shift_number + ord("a")) decoded_message += (decode_char) else: decoded_message += i print(decoded_message) #Step 2: decoded_message = "hey, how are you?" ascii_num = 0 shift_num = 0 character = "" encoded_message = "" for i in decoded_message: if i.isalpha(): ascii_num = ord(i) - ord("a") shift_num = (ascii_num - 10) % 26 character = chr(shift_num + ord("a")) encoded_message += character else: encoded_message += (i) print(encoded_message) #Step 3: ascii_number = 0 shift_number = 0 decode_char = "" decoded_message = "" def caesar_decode(message, offset): for i in message: if i.isalpha(): ascii_number = ord(i) - ord("a") shift_number = (ascii_number + offset) % 26 decode_char = chr(shift_number + ord("a")) decoded_message += (decode_char) else: decoded_message += i return decoded_message ascii_num = 0 shift_num = 0 character = "" encoded_message = "" def caesar_encode(message, offset): for i in decoded_message: if i.isalpha(): ascii_num = ord(i) - ord("a") shift_num = (ascii_num - offset) % 26 character = chr(shift_num + ord("a")) encoded_message += character else: encoded_message += (i) return encoded_message #Step 4: def caesar_decode(message, offset): ascii_number = 0 shift_number = 0 decode_char = "" decoded_message = "" for i in message: if i.isalpha(): ascii_number = ord(i) - ord("a") shift_number = (ascii_number + offset) % 26 decode_char = chr(shift_number + ord("a")) decoded_message += (decode_char) else: decoded_message += i return decoded_message message = "vhfinmxkl atox kxgwxkxw tee hy maxlx hew vbiaxkl hulhexmx. px'ee atox mh kxteer lmxi ni hnk ztfx by px ptgm mh dxxi hnk fxlltzxl ltyx." offset = 7 caesar_decode(message, offset) #Step 5: def decode_message(msg, keywrd): keywrd_phrase = "" idx = 0 for i in range(len(msg)): if msg[i].isalpha(): if idx == len(keywrd): idx = 0 keywrd_phrase += keywrd[idx] idx += 1 else: keywrd_phrase += msg[i] decoded_msg = "" for i in range(len(msg)): if msg[i].isalpha(): msg_ascii_num = ord(msg[i]) - ord('a') keywrd_ascii_num = ord(keywrd_phrase[i]) - ord('a') shift_num = (msg_ascii_num + keywrd_ascii_num) % 26 decoded_msg += chr(shift_num + ord('a')) else: decoded_msg += msg[i] return decoded_msg msg = "txm srom vkda gl lzlgzr qpdb? fepb ejac! ubr imn tapludwy mhfbz cza ruxzal wg zztcgcexxch!" keywrd = "friends" print(decode_message(msg, keywrd)) #Step 6: def encode_message(msg, keywrd): keywrd_phrase = "" idx = 0 for i in range(len(msg)): if msg[i].isalpha(): if idx == len(keywrd): idx = 0 keywrd_phrase += keywrd[idx] idx += 1 else: keywrd_phrase += msg[i] encoded_msg = "" for i in range(len(msg)): if msg[i].isalpha(): msg_ascii_num = ord(msg[i]) - ord('a') keywrd_ascii_num = ord(keywrd_phrase[i]) - ord('a') shift_num = (msg_ascii_num - keywrd_ascii_num) % 26 encoded_msg += chr(shift_num + ord('a')) else: encoded_msg += msg[i] return encoded_msg msg = "thanks for teaching me all these cool ciphers! you really are the best!" keywrd = "besties" print(encode_message(msg, keywrd)) print(decode_message(encode_message(msg, keywrd), keywrd))