Created
June 30, 2020 21:17
-
-
Save KTibow/657cc5e6f04019602b5a1cf659f3ce27 to your computer and use it in GitHub Desktop.
Simple word-shift ceaser cipher
This file contains 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 cipher(inputstr, shift=4): | |
outputstr = '' | |
for char in inputstr: | |
charnum = ord(char) - shift | |
if charnum > 122: | |
charnum = ((charnum - 97) % 26) + 97 | |
elif charnum < 97: | |
charnum = ((charnum - 97) % 26) + 97 | |
outputstr += chr(charnum) | |
return outputstr | |
def uncipher(inputstr, shift=4): | |
outputstr = '' | |
for char in inputstr: | |
charnum = ord(char) + shift | |
if charnum > 122: | |
charnum = ((charnum - 97) % 26) + 97 | |
elif charnum < 97: | |
charnum = ((charnum - 97) % 26) + 97 | |
outputstr += chr(charnum) | |
return outputstr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment