I'm working on a simple substitution-cipher decoder. I'm using frequency analysis to decrypt the ciphertext. Just looking at the frequency of unique letter isn't enough. I need to look at the occurrences of 2-letter sequences (maybe 3-letter sequences).
My code for counting the occurrences of each letter is below
int counterRaw[256][2] = {0};
for(int i = 0; i <inputString.length(); i++)
counterRaw[inputString[i]][1]++;
int counterLetter[26][2] = {0};
for(int i = 0 ; i<26 ; i++){
counterLetter[i][0] = 'A'+i;
counterLetter[i][1] = counterRaw['A'+i][1];
As you can see very simple yet effective !
But I don't know how to achieve a 2-letter sequence counter, do you have any idea which could help me to code this ?
Thanks !
EDIT : As an example Given AZAZ RTYU JKLM I want my program to output :
AZ : 2
ZA : 1
ZR : 1
RT : 1
...