Skip to content

Instantly share code, notes, and snippets.

@sblack4
Created June 6, 2017 01:51
Show Gist options
  • Save sblack4/c4f6ba7a3971c107651353bf251e4ac3 to your computer and use it in GitHub Desktop.
Save sblack4/c4f6ba7a3971c107651353bf251e4ac3 to your computer and use it in GitHub Desktop.
gets a word from the command line and decodes it using a ceasar cipher
import sys, string
def getDecodedLetter(encoded, n):
position = string.ascii_lowercase.index(encoded)
return string.ascii_lowercase[(position + n) % 26]
def getDecodedWord(word, n):
decodedWord = ""
for letter in word:
decodedWord += getDecodedLetter(letter, n)
return decodedWord
def iterateOver(word):
for i in range(1,26):
print(str(i) + " " + getDecodedWord(word, i))
if __name__ == "__main__":
for word in sys.argv[1:]:
print(word)
iterateOver(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment