Hawkynt

Shannon-Fano Coding

Variable-length prefix-free coding algorithm that predates Huffman coding. Divides symbols recursively by frequency to create binary codes, though not always optimal.

Properties

Property Value
Category Compression Algorithms
Sub-category Statistical
Security status πŸŽ“ Educational Only
Complexity Intermediate
Inventor Claude Shannon, Robert Fano
Year 1948
Origin πŸ‡ΊπŸ‡Έ United States
Source algorithms/compression/shannon-fano.js

Security

Status: πŸŽ“ Educational Only

No vulnerabilities are recorded for this implementation.

Documentation

References

Test vectors

3 vectors ship with this algorithm and run in the test suite. Byte values are hexadecimal.

Vector 1 β€” Basic frequency encoding

Field Value
input 414141424243
expected 06000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 … (518 bytes; the full value is in the source)

Vector 2 β€” Alphabet frequency test

Field Value
input 414243444546
expected 06000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 … (518 bytes; the full value is in the source)

Vector 3 β€” Repeated pattern encoding

Field Value
input 414241424142
expected 06000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 … (517 bytes; the full value is in the source)

← All algorithms