1

I've got a HashMap which stores the frequencies of each letter in a block of ciphertext, in the form of Character, Integer. The map is then sorted into a LinkedHashMap by most frequent descending.

I then compare these frequencies to a known list of letter frequencies to try and guess what the cipher letter is. The problem I've run into is if 2 or more letters occur the same number of times.

For example, if we take:

E T A O I

as the 5 most common letters desc and then letter frequencies in the cipher text:

D=30 B=25 I=22 G=19 H=17

then it would be fair to assume D maps to E as it is the most common, followed by B to T etc.

If the letter frequencies are:

D=30 B=25 I=22 G=22 H=22

It is unclear whether I, G or H should map to A as they are all the next most common after B.

I'm a little stuck and need a way of creating a set of char arrays with each permutation of the frequency list. Something like this would be needed to be output in char arrays:

DBIGH
DBIHG
DBGIH
DBGHI
DBHIG
DBHGI

Any help would be much appreciated

Maroun
  • 94,125
  • 30
  • 188
  • 241
Josh Roberts
  • 862
  • 6
  • 12

1 Answers1

0

As you said already, you need to create each permutation of the string IGH (string and char array can be used synonymously here). This question shows a solution to that problem.

To find the parts in your map for which you have to create the permutations simply iterate over your map in its frequency order and keep track of the first occurrence of the identical frequency.

Edit: Adding another idea to help with your comment. Basically you can split your 26 char string into groups of equal frequency. In the example above that would be three groups: D, B and IGH. To create all combinations of the whole string you need to combine all permutations of each group with all permutations of all other groups. For the single char groups thats trivial ofc. But once you get more groups of 3+ chars its gonna become a long list...

Community
  • 1
  • 1
SebastianH
  • 2,172
  • 1
  • 18
  • 29