0

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)

2 Answers 2

1

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'
Sign up to request clarification or add additional context in comments.

Comments

0

I believe it may be the += operator causing issues because it invokes __iadd__ instead of __add__.

Try decrypt_message1 = decrypt_message1 + decrypt_message[i]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.