Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,21 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
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(
|
||||
string.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__":
|
||||
"""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)!
|
||||
>>> u'foo'.encode('rot13')
|
||||
'sbb'
|
||||
>>> 'sbb'.decode('rot13')
|
||||
u'foo'
|
||||
|
|
|
|||
|
|
@ -1,21 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
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__":
|
||||
"""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="")
|
||||
>>> import codecs
|
||||
>>> codecs.encode("The quick brown fox jumps over the lazy dog", "rot13")
|
||||
'Gur dhvpx oebja sbk whzcf bire gur ynml qbt'
|
||||
>>> codecs.decode(_, "rot13")
|
||||
'The quick brown fox jumps over the lazy dog'
|
||||
|
|
|
|||
21
Task/Rot-13/Python/rot-13-3.py
Normal file
21
Task/Rot-13/Python/rot-13-3.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
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(
|
||||
string.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__":
|
||||
"""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)!
|
||||
21
Task/Rot-13/Python/rot-13-4.py
Normal file
21
Task/Rot-13/Python/rot-13-4.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
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__":
|
||||
"""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="")
|
||||
15
Task/Rot-13/Python/rot-13-5.py
Normal file
15
Task/Rot-13/Python/rot-13-5.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import string
|
||||
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(encode(line), end="")
|
||||
Loading…
Add table
Add a link
Reference in a new issue