-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCeaser_Cipher_Code.py
58 lines (51 loc) · 2.06 KB
/
Ceaser_Cipher_Code.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
alphabets = "abcdefghijklmnopqrstuvwxyz"
numberofletters = len(alphabets)
print("*******CEASER CIPHER*******")
def Encrypt(Plain_Text ,Key):
Cipher_Text = ''
for letter in Plain_Text :
letter = letter.lower()
if not letter == ' ':
Index = alphabets.find(letter)
if Index == -1:
Cipher_Text += letter
else:
New_Index =Index + key
if New_Index >= numberofletters:
New_Index -= numberofletters
Cipher_Text += alphabets[New_Index]
return Cipher_Text
def Decrypt(Cipher_Text ,Key):
Plain_Text = ''
for letter in Cipher_Text :
letter = letter.lower()
if not letter == ' ':
Index = alphabets.find(letter)
if Index == -1:
Plain_Text += letter
else:
New_Index =Index + key
if New_Index < 0:
New_Index += numberofletters
Plain_Text += alphabets[New_Index]
return Plain_Text
while True:
user_input = input('''What Do You Want To Do ?
1.Perform Encryption
2.Perform Decryption
3.Press 0 To Exit ''').upper()
if user_input == "1":
print("\n----You've Selected The Option To Encrypt The Plain Text Into Cipher Text----\n")
key = int(input("Enter The Key Between 1 To 26: "))
text = input("Enter The Plain Text That You Want To Encrypt: ")
Cipher_Text = Encrypt(text,key)
print(f'Your Encrypted Cipher Text is: {Cipher_Text}')
elif user_input == "2":
print("\n----You've Selected The Option To Decrypt The Cipher Text Into Original Plain Text----\n")
key = int(input("Enter The Key Between 1 To 26: "))
text = input("Enter The Plain Text That You Want To Decrypt: ")
Plain_Text = Decrypt(text,key)
print(f'Your Decrypted Plain Text is: {Plain_Text}')
else:
print("Exiting.....")
break