-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncryption and Decryption Caesar Cipher.py
78 lines (59 loc) · 1.77 KB
/
Encryption and Decryption 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
69
70
71
72
73
74
75
76
77
78
#Hajiahmad Ahmadzada Ceaser Input
#ENCRYPTION - function
def encryption(message, value):
#Making all the letters capital
message = message.upper()
#Our default key value
key = value
#Ciphered text
cipher = ""
for i in range(len(message)):
#Checking that it's alphanumeric value or not
if(not (message[i].isalnum())):
cipher += message[i]
#Work on text
else:
val = ord(message[i]) + key
if(val > 90):
val -= 26
cipher += chr(val)
return cipher
#--------------------------------------------------
#DECRYPTION - function
def decryption(message, key):
#Making all the letters capital
message = message.upper()
#Our default key value
key = 3
#Ciphered text
cipher = ""
for i in range(len(message)):
#Checking that it's alphanumeric value or not
if(not (message[i].isalnum())):
cipher += message[i]
#Work on text
else:
val = ord(message[i]) - key
if(val < 65):
val += 26
cipher += chr(val)
return cipher
#--------------------------- MAIN PART ---------------------------#
print("""
______________Ceaser Cipher Encryption System______________\n
.............. Enter 1 for encryption:
.............. Enter 2 for decryption:
""")
#Input the private key
key = int(input("Please enter the private key: "))
#Input the string to decrypt or to encrypt
message = input("Please enter your message: ")
#Command for decryption or encryption
command = int(input("_______Your command: "))
#Work-flow
if(command == 1):
print(encryption(message, key))
elif( command == 2):
print(decryption(message, key))
else:
print("ERROR! UNKNOWN COMMAND")