Ejemplo n.º 1
0
        private void btnCalcD_Click(object sender, EventArgs e)
        {
            var publicExponent = Convert.ToInt64(txtE.Text);
            var euler          = Convert.ToInt64(txtEuler.Text);
            var result         = Rsa.CalculatePrivateExponent(publicExponent, euler);
            var i = 0;

            while ((result <= 0 || result == publicExponent) && i < 5000)
            {
                publicExponent = Rsa.GeneralPublicExponent(Convert.ToInt64(txtEuler.Text), int.Parse(txtMin.Text));
                if (publicExponent > 1)
                {
                    result = Rsa.CalculatePrivateExponent(publicExponent, euler);
                }
                i++;
            }
            if (result > 0)
            {
                txtE.Text = publicExponent.ToString();
                txtD.Text = result.ToString();
                if (i > 0)
                {
                    MessageBox.Show("Giá trị publicExponent ( số mũ công khai ) ban đầu không phù hợp nên đã được tính lại.", "Sự cố trong quá trình tính toán", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("Không tính được giá trị publicExponent ( số mũ công khai ). Hãy chọn lại 2 số nguyên tố ban đầu", "Lỗi trong quá trình tính toán", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtQ.Text        = txtP.Text = "";
                btnCalcD.Enabled = btnCalcE.Enabled = false;
            }
        }