-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday8-ceaserCipher.py
More file actions
34 lines (29 loc) · 1.13 KB
/
day8-ceaserCipher.py
File metadata and controls
34 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
alphabets = ['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']
direction = input("type 'encode' to encrypt and 'decode' to decrypt: ").lower()
text = input("Enter the text: ").lower()
key = int(input("Enter the key: "))
def caeser(text, key, direction):
newText = ""
for char in text:
if char in alphabets:
index = alphabets.index(char)
if direction == "encode":
index += key
elif direction == "decode":
index -= key
index = index % 26
newText += alphabets[index]
else:
newText += char
print(f"The {direction}d text is {newText}")
while True:
caeser(text, key, direction)
again = input("Do you want to go again? 'yes' or 'no': ").lower()
if again == "yes":
direction = input("type 'encod' to encrypt and 'decode' to decrypt: ").lower()
text = input("Enter the text: ").lower()
key = int(input("Enter the key: "))
caeser(text, key, direction)
else:
print("Thank you")
break