# 对于一张png图片, 与key 进行异或操作
def xor(data, key):
key_len = len(key)
data_len = len(data)
key= data_len//key_len*key+key[:data_len%key_len]
return bytearray(a^b for a, b in zip(*map(bytearray, [data, key])))
with open("rose.png", 'rb') as f:
data = f.read()
key = b"HelloWorld"
res = xor(data, key)
with open("res2.png", 'wb') as f:
print(res)
f.write(res)
python3 异或加解密
最新推荐文章于 2023-07-24 07:43:56 发布