Example #1
0
        public static long H(string msg, long e)
        {
            IEncryptable encoder = new DESCryptoEncoder();

            string key = getKey(e);

            string coded = encoder.Encode(msg, key);

            long hash = getHash(coded);


            return(hash);
        }
Example #2
0
        private void encodeButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(inputTextArea.Text) || String.IsNullOrEmpty(keyTextBox.Text))
                {
                    throw new Exception("Не заполнены поля!");
                }
                IEncryptable encoder = new AESCryptoEncoder();
                switch ((String)cryptoType.SelectedItem)
                {
                case "DES":
                    encoder   = new DESCryptoEncoder();
                    log.Text += String.Format("Алгоритм DES c входными данными длиной {0} байт выполнился за ",
                                              inputTextArea.Text.Length * 2);
                    break;

                case "AES128":
                    encoder   = new AESCryptoEncoder();
                    log.Text += String.Format("Алгоритм AES128 c входными данными длиной {0} байт выполнился за ",
                                              inputTextArea.Text.Length * 2);
                    break;

                case "ГОСТ 28147-89":
                    encoder   = new GOSTCryptoEncoder();
                    log.Text += String.Format("Алгоритм ГОСТ 28147-89 c входными данными длиной {0} байт выполнился за ",
                                              inputTextArea.Text.Length * 2);
                    break;

                default:
                    throw new Exception("Алгоритм не выбран!");
                }

                var timer = new Stopwatch();
                timer.Start();
                outputTextBox.Text = encoder.Encode(inputTextArea.Text, keyTextBox.Text, isParallel.Checked);
                timer.Stop();
                log.Text += String.Format("{0} ms.{1}", timer.ElapsedMilliseconds, Environment.NewLine);
            }
            catch (Exception exception)
            {
                log.Text += "ERROR!" + Environment.NewLine;
                MessageBox.Show(exception.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }