function Freq = LetterFrequencies(Str) % Freq = LetterFrequencies(Str) %Input: Str = a string of upper case ciphertext %Output: Freq = a vector of percentages of occurences of each of the %letters A -> Z in Str. A summary table will also be produced in the %command window. This program calls on UCText2Int Vec = UCText2Int(Str); totChars = length(Str); %total number of characters in Str. fprintf(' Letter Frequency \r') fprintf('===============================\r') for k=0:25 Freq(k+1) = sum(Str == (65+k)*ones(size(Str)))/totChars; fprintf(' %s %f \r', char(65+k), Freq(k+1)); end; function Vec = UCText2Int(str) % Vec = UCText2Int(str) % Input: str = a string of Upper Case text (alphabet: A, B, ..., Z) % Output: Vec = the vector of corresponding nonnegative integers: % A -> 0, B->1, ..., Z -> 25 if max((str < 'A') + (str > 'Z')) > 0 error('Inputted text must only contain capital letters for UCText2Int'); end Vec = str - 'A'; %MATLAB converts arithmetic operations on strings to %their integer equivalents.