Skip to content

Instantly share code, notes, and snippets.

@baali
Created February 3, 2013 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baali/4700984 to your computer and use it in GitHub Desktop.
Save baali/4700984 to your computer and use it in GitHub Desktop.
Decryption of Rot-n encoded message
# 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