1

I am trying to make a program which can help you to break a cipher text without knowing the plain text and the key.

I want probable plain text at the output which gives the closest statistical values and a set of probable candidates keys

I started doing the frequency analysis,completed it. It helped me in telling the occurrence of each alphabet, but I have no idea how will I generate keys from that.

class Program
{
     static void Main()
     {
         // Array to store frequencies.
         int[] c = new int[(int)char.MaxValue];


         // Read entire text file.
            string s = File.ReadAllText("text.txt");


          // Iterate over each character.
          foreach (char t in s)
            {
            // Increment table.
            c[(int)t]++;
         }


          // Write all letters found.
         for (int i = 0; i < (int)char.MaxValue; i++)
         {
            if (c[i] > 0 &&
            char.IsLetterOrDigit((char)i))
            {
            Console.WriteLine("Letter: {0}  Frequency: {1}",
                (char)i,
                c[i]);
            }
         }
    }
}
4

2 回答 2

2

凯撒密码只是用字母表中固定数量的位置替换每个纯文本字符。假设没有大小写和英文文本,那么生成所有可能的 26 次解密并仅凭肉眼挑选出正确的解密是微不足道的。

对于替换密码,您需要概括您的解决方案。一种简化的方法是按照您的建议进行频率计数,然后按频率降序对字符进行排序。将它们映射到字母(同样是英文)ETAOINSRHOLUCMFYWGPBVKXQJZ(例如,假设最常见的字符代表一个 E,下一个最常见的一个 T 等等)。使用映射进行解密。您拥有的密文越多,解密效果就越好。它不太可能完全准确,但会为您提供足够的信息来手动填补空白。

更复杂的解决方案可能会从频率分布生成映射,而不仅仅是排序顺序,并使用有关语言的已知事实,例如 Q 通常后跟 U。您可以非常花哨并检查有向图和三元组频率:http:/ /practicalcryptography.com/cryptanalysis/letter-frequencies-various-languages/english-letter-frequencies/

于 2015-10-04T00:54:18.587 回答
0

对于一个简单的字母替换密码,您可能希望获得一个英文字母频率列表,并尝试将它们映射到消息中最常见的字母。注意。早在计算机出现之前,真正的军队就会在消息中插入不相关的文本来消除这种情况。在那个时候,密码学家使用的一种策略是寻找更长的重复字符串。在英语中,他们寻找三个字母的单词,例如andthenotfor。在德语中,他们寻找长的复合词,例如一个单位报告的总部的名称,或者试图猜测它会在给定的位置和时间发送什么天气报告。

于 2015-10-03T22:41:12.220 回答