如何将字符串异或python Python字节,每字节的异或解密问题,怎么解决
如何将字符串异或python
from random import seed,randint
str_in=input(请输入一个字符串:)
you_seed=input(请输入密码:)
you_seed=int(you_seed)
#lock
def my_lock(lock_str,lock_seed):
seed(lock_seed)
li_out=[]
for i in lock_str:
li_out.append(chr(ord(i)^randint(0,65535)))
return .join(li_out)
my_lock_str=my_lock(str_in,you_seed)
print(原字符串:,str_in)
print(加密字符串:,my_lock_str)
print(还原后字符串:,my_lock(my_lock_str,you_seed))
input()
#python 3.4
Python字节,每字节的异或解密问题,怎么解决
1.先将int转为hex字符串,去掉0x,然后对位数判断,比如1 --> 0x01(而不是0x1), 22 --> 0x16;
2.直接将字符串转为bytearray,比如0x123456 --> 0x12