Documentation
¶
Overview ¶
Package stats holds the cipher-agnostic statistical primitives the toolkit uses to triage a captured payload: is it plaintext, a weak classical cipher, an obfuscation, or strong encryption? Plus the repeating-key-XOR key-length estimators (Friedman/Hamming) and a crib-dragging helper for many-time-pad / keystream-reuse analysis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteFrequency ¶
ByteFrequency returns the count of each byte value.
func ChiSquareUniform ¶
ChiSquareUniform returns the chi-square statistic of the byte distribution against a uniform 256-value model. Near (256-1)=255 for uniform/random data; large for structured data.
func HammingDistance ¶
HammingDistance returns the bit-difference count between equal-length byte slices. It panics if the lengths differ — callers slice first.
func IndexOfCoincidence ¶
IndexOfCoincidence returns the probability that two bytes drawn at random (without replacement) are equal. English text over the 26-letter alphabet sits near 0.066; uniform random over 256 values near 1/256.
func ShannonEntropy ¶
ShannonEntropy returns the per-byte Shannon entropy in bits (0..8). High values (~8) indicate compression or strong encryption; low values indicate structure (plaintext, weak ciphers, obfuscation).
Types ¶
type DragHit ¶
DragHit is one crib-drag position and the plaintext fragment it reveals in the other message when two ciphertexts share a keystream (c1 ^ c2 ^ crib).
type KeyLenScore ¶
KeyLenScore pairs a candidate repeating-XOR key length with its normalized average Hamming distance (bits/byte); the true length tends to minimize it.
func GuessXORKeyLength ¶
func GuessXORKeyLength(ct []byte, maxLen int) []KeyLenScore
GuessXORKeyLength ranks candidate key lengths for a repeating-key XOR ciphertext by averaging the normalized Hamming distance between adjacent key-length blocks (the Friedman/Kasiski idea). Lower score = more likely. Results are sorted best-first.