I have a list.txt where every line has a different hex string. So I want to choose a line and convert the specific line in ascii. So I have written this code:
import codecs
f=open('list.txt')
lines=f.readlines()
var=lines[25]
print(var)
print( codecs.decode("{var}", "hex") )
The specific var = 2d560d4b0618203249312a310d5f541f295c3f0f25235c2b20037d1600f3
when I execute this command:
print( codecs.decode("2d560d4b0618203249312a310d5f541f295c3f0f25235c2b20037d1600f3", "hex") )
I get the result.
But when I try to put the var variable I get this error:
Traceback (most recent call last): File "/usr/local/lib/python3.7/encodings/hex_codec.py", line 19, in ee4'hex_decode return (binascii.a2b_hex(input), len(input))binascii.Error: Odd-length string
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main.py", line 8, in <module>
print( codecs.decode("{var}", "hex") )
binascii.Error: decoding with 'hex' codec failed (Error: Odd-length string) `