Ejemplo n.º 1
0
        private void f4_button_GetRandomCb_Click(object sender, EventArgs e)
        {
            BigInteger            P = BigInteger.Parse(f4_textP.Text);
            RandomNumberGenerator rng = RandomNumberGenerator.Create();
            BigInteger            Db, Cb = BigIntegerRandomUtils.RandomInRange(rng, 2, P - 1);

            while (!(NumberTheory.GCD(Cb, P - 1, out BigInteger x, out BigInteger y) == 1))
            {
                Cb = BigIntegerRandomUtils.RandomInRange(rng, 2, P - 1);
            }
            ;

            f4_textCb.Text = Convert.ToString(Cb);
        }
Ejemplo n.º 2
0
        private void f9_button_GetRandomSecret_Click(object sender, EventArgs e)
        {
            RandomNumberGenerator rng       = RandomNumberGenerator.Create();
            BigInteger            N         = BigInteger.Parse(f9_textN.Text);
            BigInteger            P         = BigInteger.Parse(f9_textP.Text);
            BigInteger            Q         = BigInteger.Parse(f9_textQ.Text);
            BigInteger            fi        = (P - 1) * (Q - 1); // Функция Эйлера от N
            BigInteger            SecretKey = BigIntegerRandomUtils.RandomInRange(rng, 2, N - 1);

            while (NumberTheory.GCD(SecretKey, fi, out BigInteger x, out BigInteger y) != 1)
            {
                SecretKey = BigIntegerRandomUtils.RandomInRange(rng, 2, N - 1);
            }
            f9_textSecretKey.Text = Convert.ToString(SecretKey);
        }
Ejemplo n.º 3
0
        private void f3_buttonNextGenerator_Click(object sender, EventArgs e)
        {
            f3_textP.Text = new string(f3_textP.Text.Where(t => char.IsDigit(t)).ToArray());
            f3_textQ.Text = new string(f3_textQ.Text.Where(t => char.IsDigit(t)).ToArray());
            f3_textG.Text = new string(f3_textG.Text.Where(t => char.IsDigit(t)).ToArray());

            BigInteger ParamP, ParamQ, ParamG = 0;

            if (f3_textP.TextLength > 0 && f3_textQ.TextLength > 0 && RabinMiller.IsPrime(ParamP = BigInteger.Parse(f3_textP.Text), 3) &&
                RabinMiller.IsPrime(ParamQ = BigInteger.Parse(f3_textQ.Text), 3))
            {
                RandomNumberGenerator rng = RandomNumberGenerator.Create();
                while (ParamG < 2 || ParamG >= ParamP - 1 || NumberTheory.BinaryModPow(ParamG, ParamQ, ParamP) == 1)
                {
                    ParamG = BigIntegerRandomUtils.RandomInRange(rng, 2, ParamP - 1);
                }
                f3_textG.Text = Convert.ToString(ParamG);
            }
        }
Ejemplo n.º 4
0
        private void f3_button_GetRandomSecretB_Click(object sender, EventArgs e)
        {
            RandomNumberGenerator rng = RandomNumberGenerator.Create();

            f3_textSecretB.Text = Convert.ToString(BigIntegerRandomUtils.RandomInRange(rng, DiffieHellman.Params.Q, DiffieHellman.Params.P));
        }