Created
February 19, 2018 03:11
-
-
Save JimDennis/7fef019514d84a20753d97db3f9cd61d to your computer and use it in GitHub Desktop.
Rot-13 in Python
This file contains hidden or 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
#!/usr/bin/env python | |
from __future__ import print_function | |
from string import uppercase | |
key = dict() | |
for plain,code in zip(uppercase, uppercase[13:]+uppercase[:13]): | |
key[plain] = code | |
key[plain.lower()] = code.lower() | |
def rot13(msg): | |
results = ''.join([key.get(c,c) for c in msg]) | |
return results | |
if __name__ == '__main__': | |
import fileinput, sys | |
if len(sys.argv) < 2: | |
sys.argv.append('-') | |
for line in fileinput.input(): | |
print(rot13(line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment