Python rot13加密


http://zh.wikipedia.org/wiki/ROT13

 

 1 def rot13(s, OffSet=13):
 2      def encodeCh(ch):
 3          f=lambda x: chr((ord(ch)-x+OffSet) % 26 + x)
 4          return f(97) if ch.islower() else (f(65) if ch.isupper() else ch)
 5      return ''.join(encodeCh(c) for c in s)
 6  
 7  s='Hello!'
 8  print rot13(s)              # Uryyb!
 9  print rot13(rot13(s))       # Hello!
10  print rot13(s,26)           # Hello!

 

1 def rot13_2(s,offSet=13):
2     d={chr(i+c) : chr((i+offSet) % 26 + c) for i in range(26) for c in (65,97)}
3     return ''.join([d.get(c, c) for c in s])

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM