频率分析
简单替换密码的频率分析 > 一个例子

現假設愛麗絲與鮑伯中的伊夫截獲了一段密碼（列於下方），它使用了一個簡單替換密碼進行加密：
LIVITCSWPIYVEWHEVSRIQMXLEYVEOIEWHRXEXIPFEMVEWHKVSTYLXZIXLIKIIXPIJVSZEYPERRGERIM
WQLMGLMXQERIWGPSRIHMXQEREKIETXMJTPRGEVEKEITREWHEXXLEXXMZITWAWSQWXSWEXTVEPMRXRSJ
GSTVRIEYVIEXCVMUIMWERGMIWXMJMGCSMWXSJOMIQXLIVIQIVIXQSVSTWHKPEGARCSXRWIEVSWIIBXV
IZMXFSJXLIKEGAEWHEPSWYSWIWIEVXLISXLIVXLIRGEPIRQIVIIBGIIHMWYPFLEVHEWHYPSRRFQMXLE
PPXLIECCIEVEWGISJKTVWMRLIHYSPHXLIQIMYLXSJXLIMWRIGXQEROIVFVIZEVAEKPIEWHXEAMWYEPP
XLMWYRMWXSGSWRMHIVEXMSWMGSTPHLEVHPFKPEZINTCMXIVJSVLMRSCMWMSWVIRCIGXMWYMX
在這個例子中，大寫字母表示密文，小寫字母則表示明文（或猜測在這樣），而X~t用來代表一個關於：密文X 代表明文t的猜測。
伊夫可以使用頻率分析，以下面的消息來幫助解決密文大意：單字母中I最為常見；XL是最為常見的雙字母組；而XLI則為最為常見的三字母組，且密文中找不到D。根據英文的字母分布，e是最常見的單字母，th是最為常見的雙字母組，而the則為最為常見的三字母組。因些她猜測X~t、L~h及I~e。第二個密文中最常見的字母是E；t是英文中第二常見的字母，因此應該是E~t，但由於已假設X~t，所以伊夫暫且假設E~a。姑且讓這些假設進行解碼，獲得以下的（部分）已解密消息。
heVeTCSWPeYVaWHaVSReQMthaYVaOeaWHRtatePFaMVaWHKVSTYhtZetheKeetPeJVSZaYPaRRGaReM
WQhMGhMtQaReWGPSReHMtQaRaKeaTtMJTPRGaVaKaeTRaWHatthattMZeTWAWSQWtSWatTVaPMRtRSJ
GSTVReaYVeatCVMUeMWaRGMeWtMJMGCSMWtSJOMeQtheVeQeVetQSVSTWHKPaGARCStRWeaVSWeeBtV
eZMtFSJtheKaGAaWHaPSWYSWeWeaVtheStheVtheRGaPeRQeVeeBGeeHMWYPFhaVHaWHYPSRRFQMtha
PPtheaCCeaVaWGeSJKTVWMRheHYSPHtheQeMYhtSJtheMWReGtQaROeVFVeZaVAaKPeaWHtaAMWYaPP
thMWYRMWtSGSWRMHeVatMSWMGSTPHhaVHPFKPaZeNTCMteVJSVhMRSCMWMSWVeRCeGtMWYMt
使用這些初始的猜測，伊夫發現了某些規律，來讓她可以確認其猜測，例如"that"。此外，其他規律則建議了進一步的猜測："Rtate"可能是"state"，即R~s。同樣，"atthattMZe"可以是"atthattime"，寫出M~i及Z~m。而且，"heVe"可能是"here"，給出V~r。再填入本來的密文，獲得：
hereTCSWPeYraWHarSseQithaYraOeaWHstatePFairaWHKrSTYhtmetheKeetPeJrSmaYPassGasei
WQhiGhitQaseWGPSseHitQasaKeaTtiJTPsGaraKaeTsaWHatthattimeTWAWSQWtSWatTraPistsSJ
GSTrseaYreatCriUeiWasGieWtiJiGCSiWtSJOieQthereQeretQSrSTWHKPaGAsCStsWearSWeeBtr
emitFSJtheKaGAaWHaPSWYSWeWeartheStherthesGaPesQereeBGeeHiWYPFharHaWHYPSssFQitha
PPtheaCCearaWGeSJKTrWisheHYSPHtheQeiYhtSJtheiWseGtQasOerFremarAaKPeaWHtaAiWYaPP
thiWYsiWtSGSWsiHeratiSWiGSTPHharHPFKPameNTCiterJSrhisSCiWiSWresCeGtiWYit
反過來，這些猜測還建議一些例子（例如"remarA"可能是"remark"，即A~k）。接著，相對簡單地就可推斷出其餘字母，最終產生明文：
hereuponlegrandarosewithagraveandstatelyairandbroughtmethebeetlefromaglasscasei
nwhichitwasencloseditwasabeautifulscarabaeusandatthattimeunknowntonaturalistsof
courseagreatprizeinascientificpointofviewthereweretworoundblackspotsnearoneextr
emityofthebackandalongoneneartheotherthescaleswereexceedinglyhardandglossywitha
lltheappearanceofburnishedgoldtheweightoftheinsectwasveryremarkableandtakingall
thingsintoconsiderationicouldhardlyblamejupiterforhisopinionrespectingit
到了此時，伊夫便可以加上空格及標點符號：
Hereupon Legrand arose, with a grave and stately air, and brought me the beetle
from a glass case in which it was enclosed. It was a beautiful scarabaeus, and, at
that time, unknown to naturalists—of course a great prize in a scientific point
of view. There were two round black spots near one extremity of the back, and a
long one near the other. The scales were exceedingly hard and glossy, with all the
appearance of burnished gold. The weight of the insect was very remarkable, and,
taking all things into consideration, I could hardly blame Jupiter for his opinion
respecting it.
其實這個例子是來自金甲蟲，正好伊夫的猜測全部正確。這並非總是如此，個別明文中的統計資料變化可能意味著最初的猜測並不正確。這樣可能就要做回溯法來更正錯誤或進一步推測。
明文中沒有表現出預期的字母頻率分佈也有可能。越短的消息越會表現出其更多的變化。明文本來就是經過人為扭曲的文本，例如整篇明文沒有了一些字母，通常會是最常見的「e」，這樣就稱為漏字文。