问题描述
此代码从两个二进制文件读取字节,然后使用XOR进行字节比较。基本上是从密钥文件中读取一个奇数字节,然后将其移入text.bin文件中。
密钥文件中的所有字节都是必须与text.bin文件中的字节进行比较的字节。
从技术上讲,它应该比较两个bin文件中的两个读取字节,但出现错误
output = (ord(mask)^ord(a)) # XOR
TypeError: ord() expected a character,but string of length 2 found
。
k = open ("key.bin","rb")
t = open ("text.bin","rb")
k.seek(0); t.seek(0); position = 0
while 1:
offset = k.read(1)
mask = k.read(2)
print(str(mask))
if not offset:
break
if not mask:
break
shift=int(ord(offset))
print(shift)
position = position + shift
t.seek(position)
a = t.read(1)
output = (ord(mask)^ord(a))
print (chr(output),end="")
k.close() ; d.close()
仅当mask = k.read(2)
从第二个字节读取时才会发生。
“长度为2的字符串”可能是读取了错误的十六进制字符串而不是字节?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)