decrypt_message1 + =解密消息[I]
TypeError:无法将字节连接到int。
decrypt_message1
和decrypt_message[i]
都是字节
if int(length)>=1:
for i in range(int(length)+1):
decrypt_message1=""
if i<int(length)+1:
decrypt_message1=decrypt_message1.encode()
for i in range(50):
decrypt_message1+=decrypt_message[i]
try:
decrypt = rsa.decrypt(decrypt_message1, privkey)
except Exception as E:
print(E)
decrypt=decrypt.decode()
text1.insert(END,decrypt)
else:
decrypt_message1=decrypt_message1.encode()
for i in range(len(message)-int(length)*20):
decrypt_message1+=decrypt_message[i]
try:
decrypt = rsa.decrypt(decrypt_message1, privkey)
except Exception as E:
print(E)
decrypt=decrypt.decode()
text1.insert(END,decrypt)
答案 0 :(得分:1)
decrypt_message[i]
不是bytes
个对象。它是int
:
>>> b"hello"[0]
104
变化:
decrypt_message1=decrypt_message1.encode()
for i in range(50):
decrypt_message1+=decrypt_message[i]
为:
decrypt_message1=decrypt_message1.encode()
decrypt_message1 += decrypt_message[:50]
带有bytes
索引的简单下标返回存储在该位置的整数值。
切片返回bytes
个对象。看看之间的区别:
>>> b"hello"[0]
104
和
>>> b"hello"[:1]
b'h'
答案 1 :(得分:0)
我认为可能导致问题的+=
运算符因为它调用了__iadd__
而不是__add__
。
尝试decrypt_message1 = decrypt_message1 + decrypt_message[i]