Sinkov statistic
The Sinkov statistic, also called the log-weight score, is a number that measures how much a string of letters looks like normal text in a given language. Each letter gets a weight, the Logarithm of how many times it appears per 1,000 letters of ordinary text in the language. A text's score is the sum of the weights of its letters.[1]
Codebreakers use the score to pick the right answer from many trial decryptions. The trial with the highest score is most likely the real message. The score is named after the American cryptanalyst Abraham Sinkov, who described it in his textbook Elementary Cryptanalysis, first published in 1966.[1][2][3]
Why codebreakers need a score
Many attacks on classical ciphers produce a long list of candidate texts, and only one of them is the real message. In a ciphertext-only attack on a Caesar cipher, for example, there are only 26 possible shifts. Trying them all gives 26 candidates, and exactly one is the correct Plaintext.[1]
A person can usually spot the right candidate by eye. A computer cannot, so automating the choice needs a number that is high for real text and low for gibberish.[1]
The Sinkov statistic builds that number from letter frequencies. In English, E, T, and A are common, while J, Q, X, and Z are rare. A candidate full of common letters gets a high score, and a candidate full of rare letters gets a low one.[1]
How the score is computed
The score needs a table of letter probabilities for the language and a rule for adding them up. The steps are:
- Estimate the probability of each letter from a large sample of ordinary text.
- Turn each probability into a log weight, .
- For a candidate text, look up the weight of each letter and add them.
- Do this for every candidate and keep the one with the highest total.[1]
Written as a formula, the score of a candidate text is
- is the length of the text.
- is the letter at position , and is its probability in the language.
- is the number of letters in the alphabet.
- is how many times letter appears in the text.
Every must be greater than zero, because the logarithm of zero is not defined. A letter with zero probability is left out of the alphabet.[1]
The base 10 and the factor 1000 are conventions. Multiplying by 1000 adds the same amount, , to each letter's weight. It turns the negative values into weights that are zero or positive for English, without changing which candidate ranks highest.[1]
Sample log weights for English
Common letters get high weights and rare letters get weights near zero. These values come from a published table of English log weights.[1]
| Letter | Log weight | |
|---|---|---|
| E | 127 | 2.1 |
| A | 82 | 1.9 |
| H | 61 | 1.8 |
| K | 8 | 0.9 |
| J | 2 | 0.3 |
| Q | 1 | 0.0 |
Worked example: a Caesar cipher
The word CAESAR, shifted forward by 3 letters, becomes the Ciphertext FDHVDU.[1] Shifting FDHVDU by each of the 26 possible amounts gives 26 candidate strings, and each gets a log-weight score.[1]
The correct answer stands out. CAESAR scores 10.9, the highest of all 26. The runner-up, PNRFNE, scores 10.1, and the lowest, ZXBPXO, scores 4.4.[1]
The score for CAESAR is the sum of six weights from the English table: C (1.4), A (1.9), E (2.1), S (1.8), A (1.9), and R (1.8). PNRFNE also contains common letters such as N, R, and E, which is why it comes close.[1]
Why logarithms are used
Under a simple model of language, the probability of a text is the product of the probabilities of its letters.[4] Multiplying many small probabilities gives very small numbers. In a computer this can cause arithmetic underflow, where the result is too small to store.[5]
Taking logarithms solves this. Because , the logarithm of a product of probabilities equals the sum of their logarithms.[5] Ranking candidates by this sum gives the same order as ranking them by the product.
Codebreakers working with letter groups made the same choice. Geoff Sullivan and Frode Weierud, who broke surviving German Army cipher messages in a 2005 Cryptologia paper, note that a product of group frequencies estimates how much a decryption looks like plaintext. They add that it is more convenient to store log frequencies and add them.[6]
Statistical basis
The log-weight score can be derived as a likelihood ratio, which compares how well two competing models explain the same data. Here the two models are:
- : the text comes from the language, with letter probabilities .
- : the text is random, with every letter equally likely, so each has probability .[1]
If letters are treated as independent, the counts follow a multinomial distribution. The ratio of the two probabilities is[1]
Taking the logarithm gives
The term is the same for every text of length , so only the sum matters when comparing candidates. The log-weight score equals , so for texts of the same length it ranks candidates in the same order as the likelihood ratio.[1]
Link to maximum likelihood
The same sum appears in maximum likelihood estimation. For a shift cipher, the likelihood of a key is the probability, under the language model, of the text that key produces. The maximum likelihood estimate is the key with the highest likelihood.[4]
The log-likelihood of a candidate text is , which differs from the Sinkov score only by the constant . So for a fixed ciphertext, the key with the highest Sinkov score is the maximum likelihood key under the independent-letter model.[1][4]
Comparing texts of different lengths
The raw score grows with the length of the text. Dividing the score by the length gives a log-weight rate, which lets texts of different lengths be compared.[1]
Comparison with other tests
Several other statistics also separate real text from gibberish. They differ in how much frequency information they use.
| Test | What it uses | How the best candidate is chosen |
|---|---|---|
| Most-frequent-letters test (William F. Friedman, 1918) | Counts of the 10 letters ETOANIRSHD, each weighted 1 | Highest count[1] |
| Sinkov log-weight score | Every letter, weighted by the log of its probability | Highest score[1] |
| Chi-squared test | Gaps between observed and expected letter counts | Lowest statistic[7] |
| N-gram log scores | Log probabilities of letter pairs, triples, or longer groups | Highest score[1][5] |
Friedman's test, from his Riverbank Publication No. 16 of 1918, rests on a simple fact. The letters ETOANIRSHD make up 73.9% of average English text, but would make up only of random text.[1] Sinkov's test refines it by using all single-letter frequencies, not just a split into common and other letters.[1]
In Pommerening's worked examples, the log-weight test showed no clear advantage over Friedman's simpler test, despite using finer information.[1]
Extensions to letter groups
The same idea works for pairs of adjacent letters, called bigrams. Each bigram gets a weight from its probability , scaled by 10000 because bigram probabilities are small:[1]
The score adds the weights of every bigram for . Unlike single letters, some bigrams never occur in real text, so the zero case cannot be avoided, and the rule above sets its weight to 0.[1]
Bigram scores need running text, with the letters in their original order. They do not work on the separated columns of a Vigenère cipher, where neighboring letters in a column were not neighbors in the message.[1]
Use in computer search
Computer attacks on classical ciphers often search for the key with hill climbing, which repeatedly makes a small change to the key and keeps it if the score improves.[8] Simulated annealing works the same way but sometimes keeps a worse key, which makes it less likely to get stuck at a dead end.[9] One practical guide scores each trial key in both methods by the summed log probabilities of four-letter groups, called quadgrams.[8][9]
The same guide reports that quadgrams work slightly better than trigrams, which work slightly better than bigrams. It finds that groups longer than four letters add no real benefit.[5]
Sullivan and Weierud used scores of this kind to break surviving German Army Enigma messages. Their three-pass hill climb first used the index of coincidence (the chance that two letters picked at random from the text are the same), then bigram scores, then trigram scores. This raised the success rate to around 75% for a single message.[6]
Limitations
The score rests on a simple model of language, and that model has known weak points.
- Short texts are unreliable. In one 22-letter example, the maximum likelihood shift was wrong and the true shift ranked second.[4]
- Ties can occur. In a period-4 example, the top score occurred twice for one column.[1]
- Letters and letter groups are treated as independent, which is only a rough approximation. Bigram scores even treat overlapping bigrams as independent, which can make the score less useful than expected.[1]
- The weights depend on the language. A text in another language needs its own frequency table.[1]
Longer texts help. As the ciphertext grows, the maximum likelihood estimate of the shift becomes more reliable.[4]
History
Abraham Sinkov was one of the first cryptanalysts hired by William Friedman for the U.S. Army's Signal Intelligence Service, joining in April 1930 along with Solomon Kullback. He earned a doctorate in mathematics from George Washington University in 1933. He retired from the National Security Agency in 1962 and later taught mathematics at Arizona State University.[10]
Sinkov's textbook Elementary Cryptanalysis: A Mathematical Approach was published by the Mathematical Association of America in 1966.[3] Its appendices include a table of log weights.[2] A second edition, revised by Todd Feil, appeared in 2009 and added material on RSA public-key cryptography.[11][12]
References
- Some Statistical Properties of Languages, Klaus Pommerening, Johannes Gutenberg University Mainz, n.d.
- Elementary Cryptanalysis (contents), Abraham Sinkov, Criptohistoria.
- Elementary cryptanalysis: a mathematical approach (catalogue record), Raffles Institution Library, n.d.
- Statistics 116, Breaking the Code, Lecture 1: Simple Substitution Ciphers, Stanford University, 2002.
- Quadgram Statistics as a Fitness Measure, Practical Cryptography, n.d.
- Breaking German Army Ciphers, Geoff Sullivan and Frode Weierud, Cryptologia, 2005.
- Elementary statistical methods of cryptography, Elodie Etienne, University of Liège, n.d.
- Cryptanalysis of the Simple Substitution Cipher, Practical Cryptography, n.d.
- Cryptanalysis of the Foursquare Cipher, Practical Cryptography, n.d.
- Dr. Abraham Sinkov, National Security Agency, 1999.
- Elementary Cryptanalysis, Volume 22, Abraham Sinkov and Todd Feil, MAA, 2009.
- Elementary Cryptanalysis: A Mathematical Approach, Second Edition, American Mathematical Society, 2009.
