1

我有一个HashMap将每个字母的频率存储在一个密文块中,以字符,整数的形式。LinkedHashMap然后按最频繁的降序将地图排序为 a 。

然后,我将这些频率与已知的字母频率列表进行比较,以尝试猜测密码字母是什么。我遇到的问题是,如果 2 个或更多字母出现相同的次数。

例如,如果我们采取:

E T A O I

作为 5 个最常见的字母 desc,然后是密文中的字母频率:

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

那么假设最常见的D映射是 to是公平E的,其次是BtoT等。

如果字母频率是:

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

目前尚不清楚是否或应该映射到,I因为它们都是紧随其后的下一个最常见的。GHAB

我有点卡住了,需要一种方法来创建一组 char 数组,其中包含频率列表的每个排列。需要在 char 数组中输出类似的内容:

DBIGH
DBIHG
DBGIH
DBGHI
DBHIG
DBHGI

任何帮助将非常感激

4

1 回答 1

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...

于 2014-03-17T12:37:22.070 回答