WOLFRAM|DEMONSTRATIONS PROJECT
Manipulate[Module[{chartOptions,plaintext,ciphertext,kwString,ptally,ctally},chartOptions=Sequence[AxesLabel{None,"frequency(%)"},PlotRange{Automatic,{0,14}},Axes{False,True},ImageSize{550,125},AspectRatio.20,LabelingFunction(Placed[Style[#3〚2,1〛,12,Bold],Center]&),Epilog{Red,Dashed,Line[{{0,3.85},{32,3.85}}]}];​​plaintext=StringReplace[ToLowerCase[message],CharacterRange["!","@"]..|" """];lpt=StringLength[plaintext];​​kwString=StringTake[NestWhile[#<>#&,ToLowerCase[Switch[cipher,1,StringTake[allChars,{offset+1}],2,keyword,3,keyword<>plaintext]],StringLength[#]≤lpt&],lpt];​​ciphertext=encrypt[plaintext,kwString];​​{ptally,ctally}=SortBy[#,-Last[#]&]&/@Tally/@Characters[{plaintext,ciphertext}];​​Column[{Panel[StringTake[message,75],"original message"],​​Panel[BarChart[100ptally〚All,2〛/lpt,ChartLabelsptally〚All,1〛,chartOptions]],​​Panel[StringTake[ciphertext,70],"encrypted message"],​​Panel[BarChart[100ctally〚All,2〛/lpt,ChartLabelsctally〚All,1〛,chartOptions]]}]],​​{{message,StringTake[ExampleData[{"Text","DeclarationOfIndependence"}],5000]},texts,PopupMenu},​​{{cipher,2},ciphers,PopupMenu},​​Row[{Control[{{keyword,"united"},keys,PopupMenu,Enabled(cipher>1)}],Spacer[10],Control[{{offset,13},0,25,1,Slider,ImageSizeSmall,Appearance"Labeled",Enabled(cipher==1)}]}],​​TrackedSymbolsTrue,SynchronousUpdatingFalse,Initialization(titles={"DeclarationOfIndependence","JFKInaugural","OriginOfSpecies","UNHumanRightsEnglish","DonQuixoteIEnglish"};texts=Join[Thread[StringTake[ExampleData[{"Text",#}],5000]&/@titlestitles]];​​allChars="abcdefghijklmnopqrstuvwxyz";​​keys={"x","yes","united","pelargoniums",allChars};​​ciphers=Thread[Range[3]->{"Caesar","De Vigenere","Autokey"}];​​encrypt[message_,keyword_]:=FromCharacterCode[Mod[ToCharacterCode[message]-97+ToCharacterCode[keyword]-97,26]+97])]
​
message
DeclarationOfIndependence
cipher
De Vigenere
keyword
united
offset
13
original message
When in the Course of human events, it becomes necessary for one people to
encrypted message
qumgmqnumvsxlfmhjkozigiyyablmwvrkhqhmamvivmnzrjrlbvxthictxxrxvalsoprba
Installing data from Wolfram Research data server ​
RoundFailure

Reason: Which
Tag: SecurityViolation
!MissingNotAvailable,MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DeclarationOfIndependence-6.0.9.paclet,2,
16871051442276778896]||MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DeclarationOfIndependence-6.0.9.paclet,2,
16871051442276778896]<0,0,0≤MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DeclarationOfIndependence-6.0.9.paclet,2,
16871051442276778896]≤1,100MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DeclarationOfIndependence-6.0.9.paclet,2,
16871051442276778896],True,100
%.
Installing data from Wolfram Research data server ​
RoundFailure

Reason: Which
Tag: SecurityViolation
!MissingNotAvailable,MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_JFKInaugural-6.0.9.paclet,3,16871051442276778896]||
MissingNotAvailable,MissingNotAvailable,Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_JFKInaugural-6.0.9.paclet,3,
16871051442276778896]<0,0,0≤MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_JFKInaugural-6.0.9.paclet,3,16871051442276778896]≤1,100
MissingNotAvailable,MissingNotAvailable,Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_JFKInaugural-6.0.9.paclet,3,
16871051442276778896],True,100
%.
Installing data from Wolfram Research data server ​
RoundFailure

Reason: Which
Tag: SecurityViolation
!MissingNotAvailable,MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_UNHumanRightsEnglish-6.0.9.paclet,4,
16871051442276778896]||MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_UNHumanRightsEnglish-6.0.9.paclet,4,16871051442276778896]<
0,0,0≤MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_UNHumanRightsEnglish-6.0.9.paclet,4,16871051442276778896]≤
1,100MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_UNHumanRightsEnglish-6.0.9.paclet,4,16871051442276778896],
True,100
%.
Installing data from Wolfram Research data server ​
RoundFailure

Reason: Which
Tag: SecurityViolation
!MissingNotAvailable,MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DonQuixoteIEnglish-6.0.9.paclet,5,16871051442276778896]||
MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DonQuixoteIEnglish-6.0.9.paclet,5,16871051442276778896]<0,0,
0≤MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DonQuixoteIEnglish-6.0.9.paclet,5,16871051442276778896]≤1,
100MissingNotAvailable,MissingNotAvailable,
Failure

Reason: AsynchronousTaskObject
Tag: SecurityViolation
[http://pacletserver.wolfram.com/Paclets/ExampleData_Text_DonQuixoteIEnglish-6.0.9.paclet,5,16871051442276778896],True,
100
%.
This Demonstration shows the effect of keyword length on the letter frequency of an encrypted message.
Letter frequency analysis is a common tool used for decryption. Ordered by their frequency, the letters in English text are: e, t, a, o, i, n, s, r, h, l, d, c, u, m, f, p, g, w, y, b, v, k, x, j, q, z. The efficiency of a cipher can be rated by its ability to change this "normal" order.
Monoalphabetic ciphers (like the Caesar cipher) merely shift the order of the letters but do not change the frequency distribution.
Polyalphabetic ciphers (like the De Vigenere cipher or the Autokey cipher) use a keyword. The longer the keyword, the flatter the frequency distribution and the harder the decryption.