Created
October 28, 2015 23:56
-
-
Save cruor99/78be08982589dc508829 to your computer and use it in GitHub Desktop.
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
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