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()); }
private void PrecomputedAttack(BitArray[] plainTextArray, BitArray[] cipherTextArray) { var KeyList = Precomputed.Attack(plainTextArray, cipherTextArray); StringBuilder sB = new StringBuilder("Keys found: "); foreach (var key in KeyList) { sB.Append(key); sB.Append(", "); } sB.Remove(sB.Length - 2, 2); Console.WriteLine(sB.ToString()); var goodKeys = Bruteforce.KeysForAll(KeyList, 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()); }