怎么了? Python RSA解密/

时间:2014-06-25 17:59:50

标签: python encryption rsa

  

decrypt_message1 + =解密消息[I]

     

TypeError:无法将字节连接到int。

decrypt_message1decrypt_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)

2 个答案:

答案 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]