예제 #1
0
파일: MainForm.cs 프로젝트: yan1998/Ciphers
        //Предложение размера блока в зависимости от самой короткой строки
        private void button_Propose_Click(object sender, EventArgs e)
        {
            String text = richTextBox_Input.Text;

            if (text.Length < 4)
            {
                MessageBox.Show("Для подсказки необходимо ввести текст по-длиннее!");
                return;
            }
            List <int> proposeSizes = Feistel.BlockSizePropose(text.Split('\n'));
            string     proposes     = "Оптимальные размеры блока: ";

            foreach (var item in proposeSizes)
            {
                proposes += "\n" + item;
            }
            MessageBox.Show(proposes);
        }
예제 #2
0
파일: MainForm.cs 프로젝트: yan1998/Ciphers
        private void button1_Click(object sender, EventArgs e)
        {
            pdf = new ToPDF();
            string key1 = GetKey1().ToLower(),
                   key2 = GetKey2().ToLower();

            if (key1 == "" || key2 == "")
            {
                MessageBox.Show("Ключи не могут быть пустыми!");
                return;
            }
            int    blockSize = (int)numericUpDown_BlockSize.Value;
            string text      = AddSpaces(blockSize).ToLower();

            string[] textarr = text.Split('\n');
            Feistel  feistel = new Feistel(GetKey1(), GetKey2(), Language.Russian, pdf);

            richTextBox_Output.Text = String.Empty;
            if (radioButton_Coder.Checked)
            {
                for (int i = 0; i < textarr.Length; i++)
                {
                    for (int j = 0; j < textarr[i].Length; j += blockSize)
                    {
                        richTextBox_Output.Text += feistel.Coder(textarr[i].Substring(j, blockSize));
                    }
                    richTextBox_Output.Text += "\n";
                }
            }
            else
            {
                for (int i = 0; i < textarr.Length; i++)
                {
                    for (int j = 0; j < textarr[i].Length; j += blockSize)
                    {
                        richTextBox_Output.Text += feistel.Decoder(textarr[i].Substring(j, blockSize));
                    }
                    richTextBox_Output.Text += "\n";
                }
            }
            pdf.OutToPDFFile();
        }