-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDecenc.py
39 lines (31 loc) · 1.05 KB
/
Decenc.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
# c =(x - n) % 26
def encripted(string, shift):
word = ""
for char in string:
if char == "":
word = word + char
elif char.isupper():
word = word + chr((ord(char) + shift - 65) % 26 + 65)
else:
word = word + chr((ord(char) + shift - 97) % 26 + 97)
return word
text = input("Enter the text \n")
print(text[0::])
s = int(input("Enter the shift key \n"))
print("The original text is: ", text)
print("The encrypted message is ", encripted(text, s))
def decrypt(words, shift):
word = ""
for char in words:
if char == "":
word = word + char
elif char.isupper():
word = word + chr((ord(char) - shift - 65) % 26 + 65)
else:
word = word + chr((ord(char) - shift - 97) % 26 + 97)
return word
text = input("Enter the text \n")
print(text[0::])
s = int(input("Enter the shift key \n"))
print("The original encrypted text is: ", text)
print("The decrypted message is ", decrypt(text, s).split())