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

Function encrypt

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

Source from the content-addressed store, hash-verified

38
39# Shift each letter forward to encrypt the message
40def encrypt(text, shift):
41 new_word = []
42 new_sentence = []
43 text = text.split()
44 for words in text:
45 for chosen_letter in words:
46 i = 0
47 # Find the letter and shift its position forward
48 for letter in alphabet:
49 if chosen_letter == letter:
50 new_shift = i + shift
51 new_shift = new_shift % 26
52 position = alphabet[new_shift]
53 new_word.append(position)
54 i = i + 1
55 new_word = "".join(new_word)
56 new_sentence.append(new_word)
57 new_word = []
58 new_sentence = " ".join(new_sentence)
59 print(f"the encoded message is {new_sentence}")
60
61
62# Shift each letter backward to decrypt the message

Callers 1

caesar-cipher.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected