-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCaesar_Cypher.py
45 lines (39 loc) · 1.45 KB
/
Caesar_Cypher.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
class Caesar():
def __init__(self, text):
self.text = text
def encryption(self):
alphabets = "abcdefghijklmnopqrstuvwxyz"
encrypted_text = ""
for char in text:
for alpha in alphabets:
if char == alpha:
encrypted_text += alphabets[(alphabets.index(alpha) + 3) % 26]
if char not in alphabets:
encrypted_text += char
print("Encrypted Text: ", encrypted_text)
def decryption(self):
alphabets = "abcdefghijklmnopqrstuvwxyz"
decrypted_text = ""
for char in text:
for alpha in alphabets:
if char == alpha:
decrypted_text += alphabets[(alphabets.index(alpha) - 3) % 26]
if char not in alphabets:
decrypted_text += char
print("Decrypted Text: ", decrypted_text)
while True:
choice = input(
"\n========================CAESAR-CYPHER========================\n1. Encryption\n2. Decryption\n3. Exit\nChoose operation: ")
if choice == str(1):
text = input("Enter the text to Encrypt: ")
obj = Caesar(text)
obj.encryption()
elif choice == str(2):
text = input("Enter the text to Decrypt: ")
obj = Caesar(text)
obj.decryption()
elif choice == str(3):
print("Bye")
break
else:
print("Please enter a valid choice.")