Beispiel #1
0
        private void DecryptionBruteforce(BitArray[] plainTextArray, BitArray[] cipherTextArray)
        {
            //Decryption bruteforce is faster than encryption
            var DecKeyList = new List <string>();

            for (int x = 0; x < cipherTextArray.Length; x++)
            {
                var key = Bruteforce.DecryptionAttack(plainTextArray[x], cipherTextArray[x], DecKeyList);
                if (!DecKeyList.Contains(key))
                {
                    DecKeyList.Add(key);
                }
            }
            StringBuilder sB = new StringBuilder("Keys found: ");

            foreach (var key in DecKeyList)
            {
                sB.Append(key);
                sB.Append(", ");
            }
            sB.Remove(sB.Length - 2, 2);
            Console.WriteLine(sB.ToString());
            var goodKeys = Bruteforce.KeysForAll(DecKeyList, plainTextArray, cipherTextArray);

            sB.Clear();
            sB.Append("Keys that work for all the pairs: ");
            foreach (var key in goodKeys)
            {
                sB.Append(key);
                sB.Append(", ");
            }
            sB.Remove(sB.Length - 2, 2);
            Console.WriteLine(sB.ToString());
        }