Created
June 2, 2017 10:44
-
-
Save gauravpatt92/bcb65c06fce1e5935c2b39c212824fd9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def caesar_encryption(st, shift, num): | |
new = st.lower() | |
result = "" | |
if shift=='l': | |
for i in new: | |
if i.isalpha(): | |
if ord(i)-num<97: | |
result = result + chr(122-(97-(ord(i)-num) +1)) | |
else: | |
result = result + chr(ord(i)-num) | |
else: | |
result = result + i | |
elif shift=='r': | |
for i in new: | |
if i.isalpha(): | |
if ord(i)+num>122: | |
result = result + chr(97 + ((ord(i)+num)-122 -1)) | |
else: | |
result = result + chr(ord(i)+num) | |
else: | |
result = result + i | |
return result | |
st = input("Enter the message to be encrypted: ") | |
shift = input("Enter 'l' or 'r' to mention direction of shift: " ) | |
num = int(input("Enter number of shifts: ")) | |
print("The encrypted message is : ",caesar_encryption(st, shift, num)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment