June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,21 +1,20 @@
#!/usr/bin/env python
import string
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]
)
def rot13(s):
"""Implement the rot-13 encoding function: "rotate" each letter by the
letter that's 13 steps from it (wrapping from z to a)
"""
return s.translate(
string.maketrans(
string.ascii_uppercase + string.ascii_lowercase,
string.ascii_uppercase[13:] + string.ascii_uppercase[:13] +
string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
)
)
"""Return the rot-13 encoding of s."""
return s.translate(TRANSLATION_TABLE)
if __name__ == "__main__":
"""Peform line-by-line rot-13 encoding on any files listed on our
command line or act as a standard UNIX filter (if no arguments
specified).
"""
import fileinput
for line in fileinput.input():
print rot13(line), # (Note the trailing comma; avoid double-spacing our output)!
"""rot-13 encode the input files, or stdin if no files are provided."""
import fileinput
for line in fileinput.input():
print(rot13(line), end="")

View file

@ -1,21 +1,15 @@
#!/usr/bin/env python
from __future__ import print_function
import string
def rot13(s):
"""Implement the rot-13 encoding function: "rotate" each letter by the
letter that's 13 steps from it (wrapping from z to a)
"""
return s.translate(
str.maketrans(
string.ascii_uppercase + string.ascii_lowercase,
string.ascii_uppercase[13:] + string.ascii_uppercase[:13] +
string.ascii_lowercase[13:] + string.ascii_lowercase[:13]
)
)
if __name__ == "__main__":
lets = string.ascii_lowercase
key = {x:y for (x,y) in zip(lets[13:]+lets[:14], lets)}
key.update({x.upper():key[x].upper() for x in key.keys()})
encode = lambda x: ''.join((key.get(c,c) for c in x))
if __name__ == '__main__':
"""Peform line-by-line rot-13 encoding on any files listed on our
command line or act as a standard UNIX filter (if no arguments
specified).
"""
import fileinput
for line in fileinput.input():
print(rot13(line), end="")
print(encode(line), end="")