Python_字符串简单加密解密

时间:2021-12-29 15:18:05
 def crypt(source,key):
from itertools import cycle
result=''
temp=cycle(key)
for ch in source:
result=result+chr(ord(ch)^ord(next(temp)))
return result source='Jiangxi Insstitute of Busiess and Technology'
key='zWrite' print('Before Encrypted:'+source)
encrypted=crypt(source,key)
print('After Encrypted:'+encrypted)
decrypted=crypt(encrypted,key)
print('After Decrypted:'+decrypted)
# Before Encrypted:Jiangxi Insstitute of Busiess and Technology
# After Encrypted:0>w;>Z8I6 >E9I ?
# .
# After Decrypted:Jiangxi Insstitute of Busiess and Technology