RosettaCodeData/Task/Rot-13/Python/rot-13-3.py

21 lines
550 B
Python
Raw Permalink Normal View History

2015-02-20 00:35:01 -05:00
#!/usr/bin/env python
import string
2018-06-22 20:57:24 +00:00
TRANSLATION_TABLE = str.maketrans(
string.ascii_uppercase + string.ascii_lowercase,
string.ascii_uppercase[13:] + string.ascii_uppercase[:13] +
string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
)
2015-02-20 00:35:01 -05:00
def rot13(s):
2018-06-22 20:57:24 +00:00
"""Return the rot-13 encoding of s."""
return s.translate(TRANSLATION_TABLE)
2015-02-20 00:35:01 -05:00
if __name__ == "__main__":
2018-06-22 20:57:24 +00:00
"""rot-13 encode the input files, or stdin if no files are provided."""
import fileinput
for line in fileinput.input():
print(rot13(line), end="")