Off-Platform Project: Coded Correspondence

def decode(letter):
    alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t","u", "v", "w", "x", "y", "z"]
    list_letter = letter.split()
    stripped_list_letter = []
    for word in list_letter:
            stripped_list_letter.append(word.strip())
    decoded_list = []
    for word in stripped_list_letter:
        decoded_word = ""
        for i in range(len(word)):
            if word[i] in alphabet:
                find_index = alphabet.index(word[i])
                decoded_word += alphabet[(find_index + 10) % 26]
            else:
                decoded_word += word[i]
        decoded_list.append(decoded_word)
    print(" ".join(decoded_list))

decode("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!")

Hello guys! I just finished my step1 of the Coded Correspondence Off-Platform Project. :slight_smile: . I’m glad to hear your advices for my solution. I did it myself but the only problem was the shiftes. I saw only this from the solution (find_index + 10) % 26 and i did not understand it. Can someone explain it? Thank you!

1 Like

First, alphabet.index finds the index of that letter ( which is word[i] ) and stores it as find_index ;
so find_index contains the position of the letter in alphabet.

Next, find_index + 10 finds what the index would be if shifted by 10
and doing that % 26 ensures that that number (which you’ll use an an index) is from 0 to 25
(so that there’s no error from having an invalid index).
alphabet[(find_index + 10) % 26] then gets the letter in alphabet at than new index.
decoded_word += letter adds the letter to the end of the string decoded_word (or rather, it stored a new string that contains the old string and the new letter as decoded_word

5 Likes

OK, that was really helpful. Thank you!

Are you able to go into this portion a little more? “Next, find_index + 10 finds what the index would be if shifted by 10 and doing that % 26 ensures that that number (which you’ll use an an index) is from 0 to 25 (so that there’s no error from having an invalid index).
alphabet[(find_index + 10) % 26] then gets the letter in alphabet at than new index.”

If the index of the letter is at 29 (due to a shift), then 29%26==3. How does the result of the mod (in this case 3) figure into obtaining an index within 0-25. Is it basically stating that you would take the 3rd index to be the decoded character? I’m trying to figure out how this keeps us within the index range.

I could,'t do this one it was so hard. The feeling of that is sad. Even i have some experience in python and do it for 4 -6 months already