public void runEncrypt(char key, bool encrypt)
 {
     outputTextBox.Text        = CaesarAndVigenere.caesarText(ciphertext, key, encrypt);
     caesarShiftLetterBox.Text = key.ToString();
     decryptRB.Checked         = !encrypt;
     encryptRB.Checked         = encrypt;
 }
示例#2
0
        private void findScores()
        {
            int keyLength = Int32.Parse(keyLengthTextBox.Text);

            //List<double[]> keyLetters = new List<double[]>();
            string[] textColumns = CaesarAndVigenere.vigenereColumnSeparator(parent.ciphertext, keyLength);

            for (int x = 0; x < keyLength; x++)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Letter", typeof(char));
                dt.Columns.Add("Chi-squared score", typeof(double));
                dt.Columns[0].ReadOnly = true;
                dt.Columns[1].ReadOnly = true;


                for (int i = 0; i < 26; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = (char)(i + 65);
                    dr[1] = CaesarAndVigenere.chiSquaredScore(CaesarAndVigenere.caesarText(textColumns[x], CaesarAndVigenere.ALPHABET[i], false));
                    dt.Rows.Add(dr);
                }

                dataGrids[x].DataSource = null;
                dataGrids[x].Columns.Clear();
                dataGrids[x].DataSource = dt;
                dataGrids[x].Sort(dataGrids[x].Columns[1], ListSortDirection.Ascending);

                DataGridViewCheckBoxColumn cbc = new DataGridViewCheckBoxColumn();
                dataGrids[x].Columns.Add(cbc);
                cbc.HeaderText = "Check letter";
                cbc.Name       = "checkBoxes";
                cbc.Width      = 75;
                cbc.ReadOnly   = false;
            }
            checkTopWithin20();
            //solveForKeys();
        }
        private void updateChart()
        {
            //chart1.Series["Actual Frequencies"].Points.DataBindY(CaesarAndVigenere.ALPHABET.ToArray());

            chart1.Series["English Frequencies"].Enabled = false;
            chart1.Series["Actual Frequencies"].Enabled  = false;
            chart1.Series["Frequencies of Caesar Decryption"].Enabled = false;

            string text = CaesarAndVigenere.stripText(parent.ciphertext);

            if (text.Length == 0)
            {
                return;
            }

            if (expectedFreqsCheckBox.Checked)
            {
                chart1.Series["English Frequencies"].Enabled = true;
                double[] percentageScores = CaesarAndVigenere.ENGLISH_FREQUENCIES.Select(x => 100.0 * x).ToArray();
                chart1.Series["English Frequencies"].Points.DataBindY(percentageScores);
            }

            if (userCaesarShiftCheckBox.Checked)
            {
                if (!invalidKeyLabel.Visible)
                {
                    chart1.Series["Frequencies of Caesar Decryption"].Enabled = true;
                    double   textLength       = text.Length;
                    int[]    scores           = CaesarAndVigenere.letterFrequencyAnalyser(CaesarAndVigenere.caesarText(text, caesarShiftLetterBox.Text[0], false));
                    double[] percentageScores = scores.Select(x => 100.0 * x / textLength).ToArray();
                    chart1.Series["Frequencies of Caesar Decryption"].Points.DataBindY(percentageScores);
                }
            }
            else
            {
                chart1.Series["Actual Frequencies"].Enabled = true;
                double   textLength       = text.Length;
                int[]    scores           = CaesarAndVigenere.letterFrequencyAnalyser(text);
                double[] percentageScores = scores.Select(x => 100.0 * x / textLength).ToArray();
                chart1.Series["Actual Frequencies"].Points.DataBindY(percentageScores);
            }
        }