Skip to content

Commit 7f5fb10

Browse files
authored
Update README.md
1 parent 09face0 commit 7f5fb10

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,31 @@ print("The Encrypted message is: ", encrpyted_message)
8383
This code can only be used when we know key else we have try brute force method by trying for every key value. In this method we undo the previous code to get original message.
8484

8585
```python
86+
#Create a function for Decryption algorithm
87+
def decrpyt_message(text, key):
8688

87-
```
89+
decrypted_msg = "" # initially empty string is created
90+
91+
for char in text:
92+
93+
if char.isupper(): # check character is uppercase
94+
decrypted_msg += chr((((ord(char) - key) - 65) % 26) + 65)
95+
96+
elif char.islower(): # checks character is lowercase
97+
decrypted_msg += chr((((ord(char) -key) - 97) % 26) + 97)
98+
99+
else:
100+
decrypted_msg += char # Number, spaces and special charcters are added as it is.
101+
102+
return decrypted_msg
88103

104+
text = input("Please Enter your message: ")
105+
key = int(input("Enter key value: "))
89106

107+
print("Your message: ", text)
108+
109+
decrpyted_message = decrpyt_message(text, key)
110+
print("The Decrypted message is: ", decrpyted_message)
111+
```
90112

113+
## Conclusion

0 commit comments

Comments
 (0)