Python_字符串簡單加密解密


 1 def crypt(source,key):
 2     from itertools import cycle
 3     result=''
 4     temp=cycle(key)
 5     for ch in source:
 6         result=result+chr(ord(ch)^ord(next(temp)))
 7     return result
 8 
 9 source='Jiangxi Insstitute of Busiess and Technology'
10 key='zWrite'
11 
12 print('Before Encrypted:'+source)
13 encrypted=crypt(source,key)
14 print('After Encrypted:'+encrypted)
15 decrypted=crypt(encrypted,key)
16 print('After Decrypted:'+decrypted)
17 # Before Encrypted:Jiangxi Insstitute of Busiess and Technology
18 # After Encrypted:0>w;>Z8I6    >E9I ?
19 # .
20 # After Decrypted:Jiangxi Insstitute of Busiess and Technology

 


免責聲明!

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



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