Пример #1
0
        private void Encrypt_Click(object sender, RoutedEventArgs e)
        {
            if (skital.IsChecked == true)
            {
                if (String.IsNullOrEmpty(diametr.Text))
                {
                    MessageBox.Show("Введите диаметр \"палочки\"", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                Skital skital = new Skital();
                skital.SetLength(diametr.Text);
                string original_text = origtext.Text;
                string result_text   = skital.EncryptText(original_text);
                kripttext.Text = result_text;
            }


            if (tablekript.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                TableTrans tableTrans = new TableTrans();
                tableTrans.SetKey(key1.Text);
                string original_text = origtext.Text;
                string result_text   = tableTrans.Encrypt(original_text);
                kripttext.Text = result_text;
            }


            if (doubleswitch.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите первый ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                if (String.IsNullOrEmpty(key2.Text))
                {
                    MessageBox.Show("Введите второй ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string originaText = origtext.Text;
                string cryptKeyOne = key1.Text;
                string cryptKeyTwo = key2.Text;
                try
                {
                    DoubleTrans doubleTrans = new DoubleTrans(originaText, cryptKeyOne, cryptKeyTwo);

                    string encryptString = doubleTrans.EncryptDecrypt();

                    kripttext.Text = encryptString;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            if (polib.IsChecked == true)
            {
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string      orig_text   = origtext.Text;
                PolibSquare polib       = new PolibSquare();
                string      result_text = polib.Encrypt(orig_text);
                kripttext.Text = result_text;
            }
        }
Пример #2
0
        private void Encrypt_Click(object sender, RoutedEventArgs e)
        {
            if (skital.IsChecked == true)
            {
                if (String.IsNullOrEmpty(diametr.Text))
                {
                    MessageBox.Show("Введите диаметр \"палочки\"", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                Skital skital = new Skital();
                skital.SetLength(diametr.Text);
                string original_text = origtext.Text;
                string result_text   = skital.EncryptText(original_text);
                kripttext.Text = result_text;
            }


            if (tablekript.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                TableTrans tableTrans = new TableTrans();
                tableTrans.SetKey(key1.Text);
                string original_text = origtext.Text;
                string result_text   = tableTrans.Encrypt(original_text);
                kripttext.Text = result_text;
            }


            if (doubleswitch.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите первый ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                if (String.IsNullOrEmpty(key2.Text))
                {
                    MessageBox.Show("Введите второй ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string originaText = origtext.Text;
                string cryptKeyOne = key1.Text;
                string cryptKeyTwo = key2.Text;
                try
                {
                    DoubleTrans doubleTrans = new DoubleTrans(originaText, cryptKeyOne, cryptKeyTwo);

                    string encryptString = doubleTrans.EncryptDecrypt();

                    kripttext.Text = encryptString;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            if (polib.IsChecked == true)
            {
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string      orig_text   = origtext.Text;
                PolibSquare polib       = new PolibSquare();
                string      result_text = polib.Encrypt(orig_text);
                kripttext.Text = result_text;
            }

            if (caesar.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string orig_text = origtext.Text;
                int    ces_key   = Int32.Parse(key1.Text);
                Ceasar ceasar    = new Ceasar(orig_text, ces_key);
                ceasar.Encode();
                string res_text = ceasar.GetText;
                kripttext.Text = res_text;
            }

            if (gron.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                string orig_text   = origtext.Text;
                string gron_key    = key1.Text;
                string result_text = Gronsfeld.EncryptionGronsfeld(gron_key, orig_text);
                kripttext.Text = result_text;
            }

            if (visiner.IsChecked == true)
            {
                if (String.IsNullOrEmpty(key1.Text))
                {
                    MessageBox.Show("Введите ключ", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }
                string orig_text   = origtext.Text;
                string gron_key    = key1.Text;
                string result_text = Vigenera.EncryptionVigener(gron_key, orig_text);
                kripttext.Text = result_text;
            }

            if (magicsquare.IsChecked == true)
            {
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                if (origtext.Text.Length > 16)
                {
                    MessageBox.Show("Вы ввели больше, чем 16 символов", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string      orig_text   = origtext.Text;
                MagicSquare magic       = new MagicSquare();
                var         result_text = magic.EncryptionMagicSquare(orig_text);
                kripttext.Text = "";
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        kripttext.Text += result_text[i, j].ToString();
                    }
                }
            }

            if (wheat.IsChecked == true)
            {
                if (String.IsNullOrEmpty(origtext.Text))
                {
                    MessageBox.Show("Введите текст для шифровки/расшифровки", "Ошибка", MessageBoxButton.OK);
                    return;
                }

                string     orig_text  = origtext.Text;
                WheatStone wheatStone = new WheatStone();

                string result_txt = wheatStone.Encrypt(orig_text);

                kripttext.Text = result_txt;
            }
        }