Exemple #1
0
 private void buttonDecr_Click(object sender, EventArgs e)
 {
     textBoxLog.Clear();
     if (radioButtonRSA.Checked)
     {
         if (textBoxSecretDX.Text == "" || textBoxSecretNP.Text == "")
         {
             MessageBox.Show("Закрытый ключ не введён!");
         }
         else
         if (textBoxMsg.Text == "")
         {
             MessageBox.Show("Сообщение не введено!");
         }
         else
         {
             textBoxResult.Text = RSAEncryptDecrypt.Decrypt(Convert.ToInt32(textBoxSecretDX.Text), Convert.ToInt32(textBoxSecretNP.Text), textBoxMsg.Text);
         }
     }
     else
     {
         if (textBoxSecretDX.Text == "" || textBoxSecretNP.Text == "")
         {
             MessageBox.Show("Закрытый ключ не введён!");
         }
         else
         if (textBoxMsg.Text == "")
         {
             MessageBox.Show("Сообщение не введено!");
         }
         else
         {
             textBoxResult.Text = ELGAMALEncryptDecrypt.Decrypt(Convert.ToInt32(textBoxSecretDX.Text), Convert.ToInt32(textBoxSecretNP.Text), textBoxMsg.Text);
         }
     }
 }
Exemple #2
0
        //--------------------------------
        //   Генерация ключей
        //--------------------------------
        public static void GenerateKeys(out int N, out int E, out long D)
        {
            Log.AppendText("--------------------------" + Environment.NewLine);
            Log.AppendText("Генерация ключа" + Environment.NewLine);
            Log.AppendText("--------------------------" + Environment.NewLine);

            var P         = 0;
            var Q         = 0;
            var ProstList = RSAEncryptDecrypt.ReshetoEratosfena(out P, out Q);

            N = P * Q;
            Log.AppendText("N = " + Convert.ToString(N) + Environment.NewLine);

            var M = (P - 1) * (Q - 1);

            Log.AppendText("M = " + Convert.ToString(M) + Environment.NewLine);

            E = 0;
            while (true)
            {
                var rnd = ProstList[new Random().Next(0, ProstList.Count - 1)];
                if (!EuclidIsNOD1(rnd, M))
                {
                    E = rnd;
                    break;
                }
            }
            Log.AppendText("E = " + Convert.ToString(E) + Environment.NewLine);

            D = 1;
            while (D * E % M != 1)
            {
                D++;
            }
            Log.AppendText("D = " + Convert.ToString(D) + Environment.NewLine);
        }