-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.Caesar-Cipher.py
68 lines (55 loc) · 2.13 KB
/
7.Caesar-Cipher.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
logo = """
,adPPYba, ,adPPYYba, ,adPPYba, ,adPPYba, ,adPPYYba, 8b,dPPYba,
a8" "" "" `Y8 a8P_____88 I8[ "" "" `Y8 88P' "Y8
8b ,adPPPPP88 8PP""""""" `"Y8ba, ,adPPPPP88 88
"8a, ,aa 88, ,88 "8b, ,aa aa ]8I 88, ,88 88
`"Ybbd8"' `"8bbdP"Y8 `"Ybbd8"' `"YbbdP"' `"8bbdP"Y8 88
88 88
"" 88
88
,adPPYba, 88 8b,dPPYba, 88,dPPYba, ,adPPYba, 8b,dPPYba,
a8" "" 88 88P' "8a 88P' "8a a8P_____88 88P' "Y8
8b 88 88 d8 88 88 8PP""""""" 88
"8a, ,aa 88 88b, ,a8" 88 88 "8b, ,aa 88
`"Ybbd8"' 88 88`YbbdP"' 88 88 `"Ybbd8"' 88
88
88
"""
print(logo)
cont = True
a = "abcdefghijklmnopqrstuvwxyz"
alphabet = []
for i in a:
alphabet.append(i)
def ceasar(action,text,shift):
result = []
for i in text:
if i not in alphabet:
result.append(i)
else:
pos1 = alphabet.index(i)
if action == 'encode':
pos2 = (pos1 + shift) % 26
elif action == 'decode':
pos2 = (pos1 - shift) % 26
result.append(alphabet[pos2])
print(f"Your {action}d result is: " + "".join(result))
while cont == True:
repeat = False
action = input("Type 'encode' to encrypt, type 'decode' to decrypt.\n").lower()
if action != 'encode' and action != 'decode':
print("You entered an invalid action. Try Again")
continue
text = input("Enter your message:\n").lower()
shift = int(input("Enter the shift number:\n"))
ceasar(action, text, shift)
while True:
repeat = input("Type 'Y' to continue or 'N' to close the program.\n").lower()
if repeat == "y":
break
elif repeat == 'n':
cont = False
break
else:
print("You entered an invalid option.")
continue