Reputation: 498
decrypt_message1+=decrypt_message[i]
TypeError: can't concat bytes to int.
decrypt_message1
and decrypt_message[i]
are both bytes
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)
Upvotes: 0
Views: 225
Reputation: 101909
decrypt_message[i]
is not a bytes
object. It's an int
:
>>> b"hello"[0]
104
Change:
decrypt_message1=decrypt_message1.encode()
for i in range(50):
decrypt_message1+=decrypt_message[i]
to:
decrypt_message1=decrypt_message1.encode()
decrypt_message1 += decrypt_message[:50]
Simple subscripts with an index in bytes
return the integer value stored at that position.
Slicing returns a bytes
object. See the difference between:
>>> b"hello"[0]
104
and:
>>> b"hello"[:1]
b'h'
Upvotes: 1
Reputation: 38163
I believe it may be the +=
operator causing issues because it invokes __iadd__
instead of __add__
.
Try decrypt_message1 = decrypt_message1 + decrypt_message[i]
Upvotes: 0