-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaeaser.py
32 lines (28 loc) · 980 Bytes
/
caeaser.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
def encrypt(string, shift):
cipher = ''
for char in string:
if char == ' ':
cipher = cipher + char
elif char.isupper():
cipher = cipher + chr((ord(char) + shift - 65) % 26 + 65)
else:
cipher = cipher + chr((ord(char) + shift - 97) % 26 + 97)
return cipher
def decrypt(string, shift):
cipher = ''
for char in string:
if char == ' ':
cipher = cipher + char
elif char.isupper():
cipher = cipher + chr((ord(char) + (26-shift) - 65) % 26 + 65)
else:
cipher = cipher + chr((ord(char) + (26-shift) - 97) % 26 + 97)
return cipher
text = input("Enter String : ")
s = int(input("enter Shift Number : "))
option = int(input("1. For Encrypt \n2. For Decrypt\n Enter Your choice : "))
print("Original String : ", text)
if( option == 1):
print("After Encryption : ", encrypt(text, s))
else:
print("After Decryption : ", decrypt(text, s))