Beispiel #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            BigInteger cypherText;

            BigInteger.TryParse(richTextBox7.Text, out cypherText);
            BigInteger p, q, exp;

            BigInteger.TryParse(richTextBox1.Text, out p);
            BigInteger.TryParse(richTextBox2.Text, out q);
            BigInteger.TryParse(richTextBox3.Text, out exp);
            KeysPair   keys = new KeysPair(p, q, exp);
            BigInteger text = keys.decrypt(cypherText);

            richTextBox8.Text = text.ToString();
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (richTextBox2.Text.Length == 0)
            {
                genKeys();
            }
            BigInteger p, q, exp;

            BigInteger.TryParse(richTextBox1.Text, out p);
            BigInteger.TryParse(richTextBox2.Text, out q);
            BigInteger phi = (p - 1) * (q - 1);

            BigInteger.TryParse(richTextBox3.Text, out exp);
            NumberTheory myRsa = new NumberTheory();

            if (myRsa.myGcd(exp, phi) != 1)
            {
                label4.Text      = "GCD(E, PHI(N)) != 1 \n PLEASE SELECT ANOTHER E";
                label4.ForeColor = Color.Red;
                label4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
                label4.Visible   = true;
                return;
            }
            else
            {
                label4.Text      = "    GCD(E, PHI(N)) = 1";
                label4.ForeColor = Color.Green;
                label4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
                label4.Visible   = true;
            }
            KeysPair keys       = new KeysPair(p, q, exp);
            var      publicKey  = keys.getPublicKey();
            var      privateKey = keys.getPrivateKey();

            richTextBox4.Text    = "Public key : {" + publicKey.Item1.ToString() + ", " + publicKey.Item2.ToString() + " }";
            richTextBox5.Text    = "Private key : {" + privateKey.Item1.ToString() + ", " + privateKey.Item2.ToString() + " }";
            richTextBox4.Visible = true;
            richTextBox5.Visible = true;
        }