Skip to content

Instantly share code, notes, and snippets.

@cruor99
Created October 28, 2015 23:56
Show Gist options
  • Save cruor99/78be08982589dc508829 to your computer and use it in GitHub Desktop.
Save cruor99/78be08982589dc508829 to your computer and use it in GitHub Desktop.
import string
def encode(phrase):
final = []
rot13 = string.maketrans(
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuwxyz",
"NOPQRSTUVWXYZnopqrstuwxyzABCDEFGHIJKLMabcdefghijklm"
)
for letter in phrase:
final.append(string.translate(letter, rot13))
print final
def decode(phrase):
final = []
rot13 = string.maketrans(
"NOPQRSTUVWXYZnopqrstuwxyzABCDEFGHIJKLMabcdefghijklm",
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuwxyz"
)
for letter in phrase:
final.append(string.translate(letter, rot13))
print final
def main():
print "decode or encode?"
action = raw_input()
if action == "encode":
print "enter phrase to encode"
phrase = raw_input()
encode(phrase)
elif action == "decode":
print "enter phrase to decode"
phrase = raw_input()
decode(phrase)
else:
"Not an option"
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment