Skip to content

Instantly share code, notes, and snippets.

@JimDennis
Created Feb 19, 2018
Embed
What would you like to do?
Rot-13 in Python
#!/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