I have a hex value that I'm grabbing from a text file, then I'm passing it to a2b_hex to convert it to the proper binary representation. Here is what I have:
k = open('./' + basefile + '.key', 'r')
k1 = k.read()
k.close()
my_key = binascii.a2b_hex(k1)
When I print k1, it is as expected: 81e3d6df
Here is the error message:
Traceback (most recent call last):
File "xor.py", line 26, in <module>
my_key = binascii.a2b_hex(k1)
TypeError: Odd-length string
Any suggestions? Thanks!
I suspect there is a trailing newline at the end of the file. Strip the string before passing it to binascii
.
Note there's now also a simpler spelling: k1.strip().decode('hex')
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With