private void Hack() { string text = textBoxEncryptedText.Text; hacker.Alphabet = alphabet; hacker.Analyze(text); var table1 = new Dictionary<char, double>(); var table2 = new Dictionary<char, double>(); switch (alphabet) { case Alphabet.Latin: table1 = analyzer.LatinTable; table2 = hacker.LatinTable; break; case Alphabet.Ukrainian: table1 = analyzer.UkrainianTable; table2 = hacker.UkrainianTable; break; } var query = from x in table1 orderby x.Value descending select x.Key; var query2 = from x in table2 orderby x.Value descending select x.Key; var substitutions = new Dictionary<char, char>(); for (int i = 0; i < query.Count(); i++) { substitutions.Add(query.ElementAt(i), query2.ElementAt(i)); } ObservableCollection<SubTable> collection = new ObservableCollection<SubTable>(); foreach (var s in substitutions) { collection.Add(new SubTable { Letter = s.Key, SubLetter = s.Value }); } dataGridHackerTable.ItemsSource = collection; SubstitutionCypher cipher = new SubstitutionCypher { Alphabet = alphabet }; textBoxDecryptedText.Text = cipher.Decrypt(text, substitutions); }
private void SubstitutionCypherDecrypt() { SubstitutionCypher cypher = new SubstitutionCypher { Alphabet = alphabet }; string C = textBoxEncryptedText.Text; DoEvents(); Dictionary<char, char> substitutions = new Dictionary<char, char>(); DataGrid dataGrid = gridKey.Children[1] as DataGrid; for (int i = 0; i < alphabet.GetLength(); ++i) { var letter = (dataGrid.GetCell(i, 0).Content as TextBlock).Text[0]; var subletter = (dataGrid.GetCell(i, 1).Content as TextBlock).Text[0]; substitutions.Add(letter, subletter); } textBoxDecryptedText.Text = cypher.Decrypt(C, substitutions); }