aldus.nexus

Deflate

Compress a probe's message for the long trip home with LZ77 arcs and a Huffman constellation.

Send it on through error correction

Compressed bits have no slack: one flipped bit scrambles everything after it. Here they cross the same noise three ways.

Open in error correction

The numbers

size by methodbits
symbol frequenciescolour is code length
ratio against window size
bits sent

How it works

Deflate, the method inside zip, gzip and PNG, squeezes text in two passes. First LZ77 slides a window over the message. Whenever the next few bytes already appeared inside the window, it sends a short (distance, length) pair meaning "copy this many bytes from that far back" instead of the bytes themselves.

Then Huffman coding gives every symbol left over a code whose length suits how often it appears. It keeps joining the two rarest symbols into one, so rare ones end up deep in the tree with long codes and common ones near the top with short codes. No code is the start of another, so the bits can be read back without gaps.

Both ends must agree on the codes, so Deflate never sends the tree. Codes are canonical: only each symbol's code length is sent, and the receiver rebuilds the same codes by handing out the shorter ones first, ties in symbol order. Lengths may not pass 15 bits; when a lopsided message would need longer ones, package-merge finds the best lengths that fit. Matches use two small tables: 29 length codes (3 to 258) and 30 distance codes (1 to 32,768), each followed by a few extra bits that pick the exact value.

A dynamic block's header is itself compressed. The code lengths are run-length coded with a 19-symbol code-length alphabet: 0 to 15 are lengths, 16 repeats the previous length 3 to 6 times, 17 and 18 send runs of 3 to 10 and 11 to 138 zeros. That alphabet gets its own little Huffman code (at most 7 bits), whose lengths are sent first, 3 bits each, in the order 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 so that trailing rare ones can be left off. For short messages Deflate's fixed code, with no header at all, is often smaller, and the page picks whichever wins.

The bits are a real raw Deflate stream (RFC 1951, one block, greedy matching). Your browser decompresses them with its own DecompressionStream to prove it, and its own CompressionStream output is shown for comparison.

Squeezing out the repetition also squeezes out the safety margin: a flipped bit in plain text spoils one letter, but in compressed bits it shifts every code after it. So real probes compress first and then add error correction back on top. The panel under the playback sends these bits on through noise with Hamming and Reed-Solomon codes, and the error correction page takes over the story.

repetition becomes geometry: echoes turn into arcs, and the statistics of the message grow into a tree that spells out the shortest codes.

L = Σs p(s) · len(s) ≥ H = -Σs p(s) log2 p(s)Huffman's expected code length L is within one bit of the entropy H
"abcabcabc" → a b c (3, 6)a back-reference (distance, length): copy 6 bytes starting 3 back, overlapping is allowed
length 20 → code 269 + 2 extra bits (19-22)lengths and distances send a code for a range, then extra bits for the exact value
codeₖ = next[lenₖ]++, next[l] = (next[l-1] + count[l-1]) · 2canonical codes: shorter first, ties by symbol, so lengths alone are enough