python利用异或算法实现字符串加密解密
代码:
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 ='jiangnan Institute of Business and Technology'
key = 'xxk'
print('Before Encrypted:'+source)
encrypted = crypt(source, key)#加密
print('After Encrypted:'+encrypted)
decrypted = crypt(encrypted, key)#解密
print('After decrypted:'+decrypted)
结果:

本文介绍了一种使用Python实现的简单字符串加密解密方法,通过异或算法完成数据的安全转换。源代码展示了如何使用迭代工具将任意字符串与密钥进行异或操作,实现加密与解密过程。
873

被折叠的 条评论
为什么被折叠?



