16 lines
472 B
Python
16 lines
472 B
Python
|
|
|
|
# https://stackoverflow.com/a/79038702
|
|
def hexdump(data: bytes):
|
|
def to_printable_ascii(byte):
|
|
return chr(byte) if 32 <= byte <= 126 else "."
|
|
|
|
offset = 0
|
|
while offset < len(data):
|
|
chunk = data[offset : offset + 16]
|
|
hex_values = " ".join(f"{byte:02x}" for byte in chunk)
|
|
ascii_values = "".join(to_printable_ascii(byte) for byte in chunk)
|
|
print(f"{offset:08x} {hex_values:<48} |{ascii_values}|")
|
|
offset += 16
|
|
|