Frequency Analysis:

Many simple ciphers can be cryptanalyzed by frequency analysis, that is, counting
the frequency of occurrence of each character and then comparing this to the known
frequencies of the characters in English text. The same analysis can be performed
in language or character set if Mathematica supports that character set.

For the function, we use the String Position command to find the places that each
character occurs in the string and then find the length of this list. Since we have to apply this
to 26 letters of the alphabet, it is convenient to use Map and other list
manipulation functions. The result will be a list with elements of the form
{ character,frequency}.

In[17]:=

  
  
   freq[str_]:= Transpose[ {  Characters["abcdefghijklmnopqrstuvwxyz"],
   Map[ Length[StringPosition[str,ToString[#]]] &,
                Characters["abcdefghijklmnopqrstuvwxyz"]]
               }]
   

In[18]:=

  freq[ "ghi djksiwlabc dksoabcndjdksueos"]

Out[18]


Exercise: Use this function to determine the frequency of occurrence of
letters in the English language. You should eliminate punctuation in the frequency analysis.

Exercise: Write a function to Plot the frequency distribution. For this, you can
modify the previous function to return a list of elements of the form
{ character code, frequency} where character code is a number between 0 and 25.

Up to String Manipulation