Created
February 3, 2013 08:58
-
-
Save baali/4700984 to your computer and use it in GitHub Desktop.
Decryption of Rot-n encoded message
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
# usage python rot-n.py encodedeMessage n | |
# python rot-n.py "Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf." 13 | |
import sys | |
if __name__ == '__main__': | |
encodedMsg = sys.argv[1] | |
n = int(sys.argv[2]) | |
# lets make everything lower case | |
encodedMsg = encodedMsg.lower() | |
decodedMsg = '' | |
for char in list(encodedMsg): | |
if char.isalpha(): | |
value = ord(char) + n | |
if value > ord('z'): | |
value = (value - ord('z')) + ord('a') - 1 | |
decodedMsg += chr(value) | |
else: | |
decodedMsg += char | |
print decodedMsg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment