这是我的代码:
First_xor_list=[0xaa,0x89,0xc4,0xfe,0x46]
Secpnd_xor_list=[0x78,0xf0,0xd0,0x03,0xe7]
after_xor=[]
xor_helper=[]
name = "UserNa"
after_xor.append(hex(ord(name[0])))#first stage - xor from second char to end and add the second char to the end of the list
for i in range(len(name)):
if i < len(name)-1:
after_xor.append(hex((First_xor_list[i])^ (ord(name[i+1]))))
elif i < len(name):
after_xor.append(hex(ord(name[1])))
问题是这些值作为String进入列表,这是输出:
['0x55', '0xd9', '0xec', '0xb6', '0xb0', '0x27', '0x73']
因为我必须对列表中的值进行XOR,我需要这样:
[0x55, 0xd9, 0xec, 0xb6, 0xb0, 0x27, 0x73]
如何以这种方式将它们添加到列表中?
答案 0 :(得分:1)
删除hex,hex只将int转换为包含其十六进制形式的字符串。
Active=true
答案 1 :(得分:0)
函数hex
以十六进制为基础将数字转换为字符串。
要进行计算,只需将hex
保留,并将元素保留为数字:
after_xor.append(ord(name[0])) # first stage - xor from second char to end and add the second char to the end of the list
for x, ch in zip(First_xor_list, name[1:]):
after_xor.append(x^ord(ch))
after_xor.append(ord(name[1]))