Python binascii.unhexlify TypeError: Odd-length string with non-printable character

631 Views Asked by At

I'm trying to use Python to perform binary xor operation on two strings, returning a string of ascii characters. I use binascii python module. I have the following issue with the last conversion binaryString -> ASCII characters.

I have a following code:

byteRepList = ['01111011', '00001101']
''.join(binascii.unhexlify('%x' % int(byte, 2)) for byte in byteRepList)

While 01111011 => '{', 00001101 => nothing.

So TypeError: Odd-length string is beeing thrown.

Could someone please advise, what should I properly do with it? I would still like to get string output.

1

There are 1 best solutions below

0
On

In the end my solution to this issue was just to try-catch the TypeError and pass in the catch block.