private CrackResult[] FixVigenere(CrackResult[] results) { double min = 0.3; string vigenereKey = string.Empty; if (results.Length > 0 && results.First().cipher is Vigenere) { vigenereKey = results.First().key; double distinct = (double)vigenereKey.ToCharArray().Distinct().Count(); double origin = (double)vigenereKey.Length; double poss = distinct / origin; if (poss < min) { return results.Where(x => x.cipher is Caesar).ToArray(); } } return results; }
private static List<CrackResult> GetCrackResults(string ciphertext, Cipher[] ciphers, Storage.Languages language) { List<CrackResult> results = new List<CrackResult>(); foreach (var cipher in ciphers) { try { var keys = cipher.Crack(ciphertext, 0, language); if (keys.Count > 0) { var result = new CrackResult(); result.key = keys[0]; result.opentext = cipher.Decrypt(ciphertext, result.key); result.cipher = cipher; results.Add(result); } } catch (Exceptions.MatchNotFound) { } } return results; }
private void GetCrackResults(string ciphertext, Cipher[] ciphers, Storage.Languages language, Action<CrackResult[]> afterCrack) { int threadsCount = ciphers.Length; CrackResult[] results = new CrackResult[threadsCount]; bool[] syncArray = new bool[threadsCount].Fill(false); object progressLockObject = new object(); object endTestLockObject = new object(); threadsCount.Times(i => { Thread thread = new Thread(() => { try { var currentCipher = ciphers[i]; var keys = currentCipher.Crack(ciphertext, 0, language); if (keys.Count > 0) { var crackResult = new CrackResult(); crackResult.key = keys[0]; crackResult.opentext = currentCipher.Decrypt(ciphertext, crackResult.key); crackResult.cipher = currentCipher; results[i] = crackResult; } else { throw new Exceptions.MatchNotFound(); } lock (progressLockObject) { progress(); } } catch (Exceptions.MatchNotFound) { lock (progressLockObject) { progress(); } } lock (endTestLockObject) { syncArray[i] = true; if (syncArray.All(x => x)) { afterCrack(results); } } }); thread.Priority = ThreadPriority.Lowest; thread.IsBackground = true; addThread(thread); thread.Start(); }); }
private void finish(CrackResult crackResult) { if (FinishFunction != null) FinishFunction(crackResult); }
private void SetCrackResult(CrackResult result, string ciphertext) { SetCrackResult(result.key, result.cipher.Decrypt(ciphertext, result.key), Storage.GetCipherName((Storage.Ciphers)Enum.Parse(typeof(Storage.Ciphers), result.cipher.ToString()))); }