Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 needUseEntry
Entropy, cross entropy, divergence or mutual information; a Gray codeentropy, entropy_from_probabilities, cross_entropy, kl_divergence, mutual_information, gray_codeEntropy and information
Compression by symbol frequencieshuffman, shannon_fano, arithmetic (or the SourceCoder wrappers)Entropy coding
Compression by repeated stringslz77, lz78, lzwDictionary coding
A pseudo-noise sequence, a primitive polynomial or a set of spreading codesLfsr, is_primitive_polynomial, maximum_length_polynomial, gold_codesLFSRs and Gold codes
A checksum or a cryptographic digestcrc32, crc32c, Crc32, sha256, Sha256Checksums and hashes