Hey everyone, I am looking for a code review for the coded correspondence project in the Business Intelligence Data Analyst career path. I am 33% complete with the career path. I must say, this project threw me for a loop. It seemed much more difficult than what I have learned thus far in the career path. I had to use AI to help with most of it. I’m feeling a little discouraged as a result of this. If anyone would be willing to go in depth with explaining the code I would really appreciate it. I am also wondering if this project is considered a pretty advanced project or not? I am also looking for formatting tips (like if I should have all the functions at the top or not). Sorry I have a lot of questions.
def decode_vishal_cipher(message, offset):
lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
decoded_message = ""
for char in message:
if char in lower:
original_index = (lower.index(char) - offset) % 26
decoded_char = lower[original_index]
decoded_message += decoded_char
elif char in upper:
original_index = (upper.index(char) - offset) % 26
decoded_char = upper[original_index]
decoded_message += decoded_char
else:
decoded_message += char
return decoded_message
def encode_vishal_cipher(message, offset):
lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
encoded_message = ""
for char in message:
if char in lower:
original_index = (lower.index(char) + offset) % 26
encoded_char = lower[original_index]
encoded_message += encoded_char
elif char in upper:
original_index = (upper.index(char) + offset) % 26
encoded_char = upper[original_index]
encoded_message += encoded_char
else:
encoded_message += char
return encoded_message
def try_decode_with_offsets(encrypted_message, target_word):
decoded_message = None
decoded_offset = None
for offset in range(26):
current_decoded_message = decode_vishal_cipher(encrypted_message, offset)
if target_word.lower() in current_decoded_message.lower():
decoded_message = current_decoded_message
decoded_offset = offset
break
if decoded_message is not None:
print(f"Decoded message found with offset {decoded_offset}: {decoded_message}")
else:
print("No valid decoded message found.")
def vigenere_decrypt(cipher_message, keyword):
keyword_text = ""
index = 0
for char in range(len(cipher_message)):
if cipher_message[char].isalpha():
if index == len(keyword):
index = 0
keyword_text += keyword[index]
index += 1
else:
keyword_text += cipher_message[char]
decoded_message = ""
for char in range(len(cipher_message)):
if cipher_message[char].isalpha():
message_ascii_num = ord(cipher_message[char])-ord('a')
keyword_ascii_num = ord(keyword_text[char])-ord('a')
shift_num = (message_ascii_num + keyword_ascii_num) %26
decoded_message += chr(shift_num + ord('a'))
else:
decoded_message += cipher_message[char]
return decoded_message
def vigenere_encrypt(cipher_message, keyword):
keyword_text = ""
index = 0
for char in range(len(cipher_message)):
if cipher_message[char].isalpha():
if index == len(keyword):
index = 0
keyword_text += keyword[index]
index += 1
else:
keyword_text += cipher_message[char]
encoded_message = ""
for char in range(len(cipher_message)):
if cipher_message[char].isalpha():
message_ascii_num = ord(cipher_message[char])+ord('a')
keyword_ascii_num = ord(keyword_text[char])+ord('a')
shift_num = (message_ascii_num - keyword_ascii_num) %26
encoded_message += chr(shift_num + ord('a'))
else:
encoded_message += cipher_message[char]
return encoded_message
encrypted_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"
decoded_message = decode_vishal_cipher(encrypted_message, -10)
print(decoded_message)
response_to_vishal = "hey! i was able to encrypt your message!"
encoded_response = encode_vishal_cipher(response_to_vishal, -10)
print(encoded_response)
encrypted_message_2 = "jxu evviuj veh jxu iusedt cuiiqwu yi vekhjuud."
decoded_message_2 = decode_vishal_cipher(encrypted_message_2,-10)
print(decoded_message_2)
encrypted_message_3 = "bqdradyuzs ygxfubxq omqemd oubtqde fa oapq kagd yqeemsqe ue qhqz yadq eqogdq!"
decoded_message_3 = decode_vishal_cipher(encrypted_message_3,-14)
print(decoded_message_3)
encrypted_message_4 = "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"
try_decode_with_offsets(encrypted_message_4, 'the')
cipher_message = 'txm srom vkda gl lzlgzr qpdb? fepb ejac! ubr imn tapludwy mhfbz cza ruxzal wg zztylktoikqq!'
keyword = "friends"
decrypted_message = vigenere_decrypt(cipher_message, keyword)
print("Decrypted message:")
print(decrypted_message)
cipher_message_2 = "i was able to decode this, it was extremely difficult"
keyword_2 = "friends"
encrypted_message = vigenere_encrypt(cipher_message_2, keyword_2)
print("Encrypted Message: ")
print(encrypted_message)
Hello,
I am working on the same project, in the ‘Data Science: Natural Language Processing Specialist’ career path.
It does feel pretty advanced & difficult. Unfortunately, I am not the one to ask for explaining the code, as I’m having problems with it as well, working on it for multiple days & having to use a little bit of AI assistance also to try to get it right. I wouldn’t know yet the proper formatting for the code either.
I hope you were able to finish it being it was last week when you posted this, i.e. 6 days ago already, the previous projects in this ‘career path’ course were pretty easy in comparison to how this project is.
Good luck & you can do it.
Kevin
Hey Kevin,
I really appreciate you sharing your experience with the project with me. I haven’t really worked on the career path this past week as this project discouraged me and felt like I needed to take a break and just focus on work. I hope someone can lead us in the right direction on here.
Good luck to you as well.
Owen
Hey ob11! I get it—some projects feel like a big leap. This one is definitely more advanced, so don’t be too hard on yourself. Structuring functions at the top is a good practice, but clarity matters most. When I hit tough coding challenges, I take a break and read Surah Yaseen (https://suraheyaseen.com/)—it helps me reset. Keep going, you’re doing great!