Lion Cipher Lab

Build Huffman coding from scratch, and measure it against the entropy bound

Why it matters

Entropy shows up all over security tooling. Ransomware detectors flag files that 'look encrypted'. Exfiltration hunts flag payloads that 'look random'. Malware triage flags sections that 'look packed'. Most of that tooling uses one number, and most people who read it could not say what the number measures or when it lies. This lab fixes that by building the thing the number describes. Shannon's entropy is a floor: the fewest bits per byte any coder could reach if all it knows is how often each byte appears. Huffman coding is the classic way to get close to that floor. Your coder will land…

What you'll learn

Steps in this lab

  1. What you are building, and what a bit of information is
  2. Set up: Python, a terminal, and a lab folder
  3. Make the test inputs (all local, mostly seeded)
  4. Measure entropy, and read it as a floor
  5. Build the Huffman tree with a heap
  6. Canonical codes, a 264-byte header, bit packing, and a decoder
  7. Huffman vs the entropy floor vs real compressors
  8. Honest negatives: random data, small files, and a biased H1
  9. 'High entropy' is a weak signal for 'encrypted' -- measured
  10. Compress BEFORE you encrypt, never after (and the one exception to know)
  11. Do it better: how to use entropy like a pro, then clean up

Open the full interactive lab →