Hex

Hex

#!/usr/bin/python3
import sys
with open(sys.argv[1], "rb") as f:
    data = f.read()
for offset in range(0, len(data), 16):
    b = data[offset:offset + 16]
    left = " ".join(f"{x:02x}" for x in b[:8])
    right = " ".join(f"{x:02x}" for x in b[8:])
    hexpart = f"{left:<23}  {right:<23}"
    text = "".join(chr(x) if 32 <= x <= 126 else "." for x in b)
    print(f"{offset:08x}  {hexpart}  |{text}|")

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment