Information theory: source coding, LFSRs, checksums and hashes
Information theory asks how compactly data can be described and how reliably it can be sent. This chapter covers the first question and its neighbours: the measures of information, the lossless compressors that approach those limits, the shift-register sequences that look random but are generated by a few gates, and the checksums and hashes that detect corruption. The error-correcting codes of the next chapter take up the second question.
The central questions
- How much information is there? The entropy of a source bounds lossless compression; real data’s structure between symbols makes its true entropy rate far lower than its symbol entropy.
- Model or dictionary? Entropy coders need the symbol probabilities; dictionary coders learn repeated strings without any model, and practical compressors combine the two.
- Random or structured? LFSR sequences are perfectly predictable yet have the balance and correlation of noise, which is what ranging and spread spectrum need.
- Accident or adversary? A CRC catches the errors a channel makes; only a cryptographic hash resists someone choosing the errors.
Testing against Python and SciPy
The references come from Python 3.13’s zlib, hashlib, bz2 and lzma modules and from SciPy 1.17.1, by book/generator/data/make_information_refs.py. The entropy and divergences agree with scipy.stats.entropy to 12 digits, the CRC-32 and SHA-256 values are identical on every test input, and all six compressors
reproduce the 4.6 MB test text exactly.
In the library
All of these are in lib_jsl_information (API reference).
| You need | Use | Entry |
|---|---|---|
| Entropy, cross entropy, divergence or mutual information; a Gray code | entropy, entropy_from_probabilities, cross_entropy, kl_divergence, mutual_information, gray_code | Entropy and information |
| Compression by symbol frequencies | huffman, shannon_fano, arithmetic (or the SourceCoder wrappers) | Entropy coding |
| Compression by repeated strings | lz77, lz78, lzw | Dictionary coding |
| A pseudo-noise sequence, a primitive polynomial or a set of spreading codes | Lfsr, is_primitive_polynomial, maximum_length_polynomial, gold_codes | LFSRs and Gold codes |
| A checksum or a cryptographic digest | crc32, crc32c, Crc32, sha256, Sha256 | Checksums and hashes |