diff --git a/hexdump.py b/hexdump.py new file mode 100644 index 0000000..95f7bc9 --- /dev/null +++ b/hexdump.py @@ -0,0 +1,15 @@ + + +# 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 +