灵活的Rot13功能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了灵活的Rot13功能相关的知识,希望对你有一定的参考价值。
This function takes 2 arguments, first is the string to be encoded (or decoded) the second is optional and can be used to change the rotation amount to something other than 13.
def rot(s, n=13): r = "" for c in s: cc = c if cc.isalpha(): cc = cc.lower() o = ord(cc) ro = (o+n) % 122 if ro == 0: ro = 122 if ro < 97: ro += 96 cc = chr(ro) r = ''.join((r,cc)) return r
以上是关于灵活的Rot13功能的主要内容,如果未能解决你的问题,请参考以下文章