CHI SQUARE

The Chi-Square test is used to compare two ciphertext frequency distributions to determine if the ciphers were enciphered with the same key or which columns of a periodic cipher were calculated with the same key. This is acheived by comparing the observed frequency of text with the expected frequency. It was developed by the U.S. Government Cryptographer William F. Friedman (1891-1969) and the technique was declassified and published by the author in the National Security Agency in the publication Military Cryptanalytics, Part III in 1939.

The formula to calculate the Chi-Square is:

where Ci is the frequency of each letter A to Z and Ei is the expected frequency of each letter. The lower the result the better fit to the expected frequency it is.

For example, using the Caesar cipher text:

EHLQJ SUHVL GHQWL VOLNH UXQQL QJDFH PHWHU BBRXY HJRWD ORWRI SHRSO HXQGH UBRXD QGQRE RGBVO LVWHQ LQJZL OOLDP MFOLQ WRQ

The Chi-Square value is 15.02 whereas the Chi-Square value of the following text is 0.56 suggesting this is most like English.

BEING PRESI DENTI SLIKE RUNNI NGACE METER YYOUV EGOTA LOTOF PEOPL EUNDE RYOUA NDNOB ODYSL ISTEN INGWI LLIAM JCLIN TON