- def rot13(s, OffSet=13):
- def encodeCh(ch):
- f=lambda x: chr((ord(ch)-x+OffSet) % 26 + x)
- return f(97) if ch.islower() else (f(65) if ch.isupper() else ch)
- return ''.join(map(encodeCh,s))
- s='Hello!'
- print rot13(s) # Uryyb!
- print rot13(rot13(s)) # Hello!
- print rot13(s,26) # Hello!
- #该片段来自于http://www.codesnippet.cn/detail/290520133652.html
来源: http://www.codesnippet.cn/detail/290520133652.html