public static Dictionary <string, string> Attack(byte[] cipher) { var outputs = new Dictionary <string, string>(); foreach (byte key in Enumerable.Range(0, 127)) { var expandedKey = Key.Expand(key, cipher); var outputBytes = Xor.CompareByteArrays(cipher, expandedKey); outputs.Add(key.ToString(), Encoding.ASCII.GetString(outputBytes)); } return(outputs); }
public static DecryptionResult AnalyzeResult(List <Dictionary <string, string> > bruteForceResults, byte[] cipherBytes) { var fullKey = AnalyzeKey(bruteForceResults); // Use key! var expandedKey = Key.Expand(fullKey, cipherBytes); var plainTextAsBytes = Xor.CompareByteArrays(cipherBytes, expandedKey); var plaintext = Encoding.UTF8.GetString(plainTextAsBytes); return(new DecryptionResult { RepeatingKey = Encoding.ASCII.GetString(fullKey), DecryptedText = plaintext }); }