← All writings

Writing · Ep. 6 · 0x09EA–0x0A90 · Tools

Coloring hex dumps by entropy

Staring at a wall of hex is slow. Coloring it by entropy turned out to be the fastest way to see where a file's structure changes — so I built Hex Garden.

The idea

Split the file into 256-byte blocks and compute how "random" each block looks. Headers and tables are low, text is in the middle, and compressed data is near the maximum of 8 bits per byte.

function entropy(block) {
  const counts = new Array(256).fill(0);
  for (const byte of block) counts[byte]++;
  let h = 0;
  for (const c of counts) if (c) { const p = c / block.length; h -= p * Math.log2(p); }
  return h;
}

What it found

In the OreGairu English Patch archives, the entropy map showed the table of contents, the compressed script files, and long runs of padding at a glance.