MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / decrypt

Function decrypt

web/public/playground/caesar-cipher.py:63–84  ·  view source on GitHub ↗
(text, shift)

Source from the content-addressed store, hash-verified

61
62# Shift each letter backward to decrypt the message
63def decrypt(text, shift):
64 alphabet.reverse()
65 new_word = []
66 new_sentence = []
67 text = text.split()
68 for words in text:
69 for chosen_letter in words:
70 i = 0
71 # Find the letter in reversed alphabet and shift
72 for letter in alphabet:
73 if chosen_letter == letter:
74 new_shift = i + shift
75 new_shift = new_shift % 26
76 position = alphabet[new_shift]
77 new_word.append(position)
78 i = i + 1
79 new_word = "".join(new_word)
80 new_sentence.append(new_word)
81 new_word = []
82 new_sentence = " ".join(new_sentence)
83 print(f"the decoded message is {new_sentence}")
84 alphabet.reverse()
85
86
87# Run encrypt or decrypt based on user's choice

Callers 1

caesar-cipher.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected