示例#1
0
        public async void CreateAndStartThreadHiper(int par)
        {
            try
            {
                GenKeytextBox.Text   = "";
                genTextKeylabel.Text = "";
                byte[] key           = null;
                var    reg           = new Regex(@"(^\d+| \d+)");
                var    byteStringCol = reg.Matches(KeytextBox.Text);

                key = new byte[byteStringCol.Count];
                for (int i = 0; i < byteStringCol.Count; i++)
                {
                    genTextKeylabel.Text += byteStringCol[i].Value + " ";
                    int keyint = Int32.Parse(byteStringCol[i].Value);
                    if (keyint > 255)
                    {
                        throw new Exception("Введите числа от 1 до 255 через пробел");
                    }
                    key[i] = Byte.Parse(byteStringCol[i].Value);
                }


                RC4 rc4 = new RC4(key);

                rc4.secKeyBite += (strKey) => {
                    Action textkey = () => GenKeytextBox.Text += strKey + " ";
                    if (InvokeRequired)
                    {
                        Invoke(textkey);
                    }
                    else
                    {
                        textkey();
                    }
                };
                panelProgress.Visible = true;
                rc4.ProgressChange   += progressChange;                                            //подписываемся для отображения прогресса на форме
                await Task.Run(() => rc4.CipherFile(pathTextBox.Text, savePathTextBox.Text, par)); //Асинхронно запускаем метод для шифрования или дешифрования файла

                panelProgress.Visible = false; MessageBox.Show("Успешно");
                panelControlFalseInChipering.Enabled = true;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); panelControlFalseInChipering.Enabled = true; }  //Если произошла ошибка выводим ее
        }
示例#2
0
文件: Form1.cs 项目: inickzac/Csharp
        public async void CreateAndStartThreadHiper(int par)
        {
            try
            {
                OriginalTexttextBox.Text = "";
                ProcessTextBox.Text      = "";
                GenKeytextBox.Text       = "";
                Keylabel.Text            = "";
                ICipher icipher = null;
                if (savePathTextBox.Text != "" || saveFileDial.ShowDialog() == DialogResult.OK)
                {
                    savePathTextBox.Text = saveFileDial.FileName;
                }
                else
                {
                    throw new Exception("Выберите путь сохранения файла");
                }
                panelControlFalseInChipering.Enabled = false;
                Keylabel.Enabled      = true;
                KeyOriglabel.Enabled  = true;
                panelProgress.Visible = true;
                if (ciperLFSRRadioBut.Checked || GeffeRadioBut.Checked)
                {
                    System.Collections.BitArray[] initialState = new System.Collections.BitArray[3];

                    if (ciperLFSRRadioBut.Checked)
                    {
                        initialState[0] = converToBitArray(29, LFSR1Textbox.Text);
                        initialState[1] = null;
                        Keylabel.Text   = "LFSR1 " + LFSR1Textbox.Text;
                    }
                    if (GeffeRadioBut.Checked)
                    {
                        initialState[0] = converToBitArray(29, LFSR1Textbox.Text);
                        initialState[1] = converToBitArray(37, LFSR2Textbox.Text);
                        initialState[2] = converToBitArray(27, LFSR3Textbox.Text);
                        Keylabel.Text   = " LFSR1 " + LFSR1Textbox.Text + " LFSR2 " + LFSR2Textbox.Text + " LFSR3 " + LFSR3Textbox.Text;
                    }

                    icipher = new LFSR(initialState);
                }
                if (RC4RadioBut.Checked)
                {
                    if (RC4textBox.Text == "")
                    {
                        throw new Exception("Введите ключ rc4");
                    }
                    byte[] key = ASCIIEncoding.ASCII.GetBytes(RC4textBox.Text);
                    foreach (byte bt in key)
                    {
                        Keylabel.Text += " " + Convert.ToString(bt, 2);
                    }
                    icipher = new RC4(key);
                }

                icipher.ProgressChange  += progressChange;
                icipher.secOriginalByte += (byteInt) => {
                    Action ChangeText = () => OriginalTexttextBox.Text += byteInt + " ";
                    if (InvokeRequired)
                    {
                        Invoke(ChangeText);
                    }
                    else
                    {
                        ChangeText();
                    }
                };
                icipher.secChiperByte += (byteInt) => {
                    Action ChangeText = () => ProcessTextBox.Text += byteInt + " ";
                    if (InvokeRequired)
                    {
                        Invoke(ChangeText);
                    }
                    else
                    {
                        ChangeText();
                    }
                };
                icipher.secKeyBite += (byteInt) => {
                    Action ChangeText = () => GenKeytextBox.Text += byteInt + " ";
                    if (InvokeRequired)
                    {
                        Invoke(ChangeText);
                    }
                    else
                    {
                        ChangeText();
                    }
                };
                await Task.Run(() => icipher.CipherFile(pathTextBox.Text, savePathTextBox.Text, par));

                panelProgress.Visible = false; MessageBox.Show("Успешно");
                panelControlFalseInChipering.Enabled = true;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); panelControlFalseInChipering.Enabled = true; }
        }