Skip to content

Commit c4ab7ba

Browse files
authored
Create Decryption-python-code.py
1 parent 7f5fb10 commit c4ab7ba

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Decryption-python-code.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Create a function for Decryption algorithm
2+
def decrpyt_message(text, key):
3+
4+
decrypted_msg = "" # initially empty string is created
5+
6+
for char in text:
7+
8+
if char.isupper(): # check character is uppercase
9+
decrypted_msg += chr((((ord(char) - key) - 65) % 26) + 65)
10+
11+
elif char.islower(): # checks character is lowercase
12+
decrypted_msg += chr((((ord(char) - key) - 97) % 26) + 97)
13+
14+
else:
15+
decrypted_msg += char # Number, spaces and special charcters are added as it is.
16+
17+
return decrypted_msg
18+
19+
text = input("Please Enter your message: ")
20+
key = int(input("Enter key value: "))
21+
22+
print("Your message: ", text)
23+
24+
decrpyted_message = decrpyt_message(text, key)
25+
print("The Decrypted message is: ", decrpyted_message)

0 commit comments

Comments
 (0)