public void runEncrypt(string key, bool encrypt) { outputTextBox.Text = CaesarAndVigenere.vigenereText(ciphertext, key, encrypt); keyTextBox.Text = key.ToString(); decryptRB.Checked = !encrypt; encryptRB.Checked = encrypt; }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // Get array of checked letters List <char[]> checkedLetterLists = new List <char[]>(); foreach (DataGridView dgv in dataGrids) { List <char> checkedLetters = new List <char>(); foreach (DataGridViewRow row in dgv.Rows) { DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)(row.Cells["checkBoxes"]); if (Convert.ToBoolean(cell.Value)) { checkedLetters.Add((char)(row.Cells["Letter"].Value)); } } checkedLetterLists.Add(checkedLetters.ToArray()); } // Get array of keys string[] keys = CaesarAndVigenere.joinPossibleKeys(checkedLetterLists.ToArray()); // Make DataTable for the final output DataGridView resultsTable = new DataTable(); resultsTable.Columns.Add("Key", typeof(string)); resultsTable.Columns.Add("Chi-squared score", typeof(double)); resultsTable.Columns.Add("Decrypted text", typeof(string)); for (int i = 0; i < keys.Length; i++) { string key = keys[i]; DataRow newRow = resultsTable.NewRow(); string decryptedText = CaesarAndVigenere.vigenereText(parent.ciphertext, key, false); //Console.WriteLine(decryptedText.Length); newRow[0] = key; newRow[1] = CaesarAndVigenere.chiSquaredScore(decryptedText); newRow[2] = decryptedText; resultsTable.Rows.Add(newRow); ((BackgroundWorker)sender).ReportProgress((i * 1000) / keys.Length); } // Push to the DGV }