python - Convert(decode) hex string to ASCII or any other understandable format -


b'7668647866696c654d006900630072006f0073006f00660074002000570069006e0064006f0077007300200036002e0033002e0039003600300030002e003100370033003900360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' 

i want convert hex string ascii or readable text. getting block system image file.

expanding on joran's answer,

import string data = bytes.fromhex(b'7668647866696c654d006900630072006f0073006f00660074002000570069006e0064006f0077007300200036002e0033002e0039003600300030002e003100370033003900360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.decode("ascii")) print("".join(chr(c) if chr(c) in string.printable else '.' c in data)) 

result:

vhdxfilem.i.c.r.o.s.o.f.t. .w.i.n.d.o.w.s. .6...3...9.6.0.0...1.7.3.9.6......................................................................................................................................................................................... 

note won't give perfect lossless representation of data - unreadable characters replaced periods. it's suitable if you're searching textual data.


Popular posts from this blog