示例#1
0
        protected override void DoExecute()
        {
            FireOnStart();

            try
            {
                BigInteger second = BigInteger.Parse(m_SecondParameter.ToString());
                BigInteger from = BigInteger.Parse(m_From.ToString());
                BigInteger to = BigInteger.Parse(m_To.ToString());
                BigInteger a, b;

                for (BigInteger x = from; x <= to; x++)
                {
                    string msg;

                    try
                    {
                        BigInteger gcd = BigIntegerHelper.ExtEuclid(x, second, out a, out b);
                        string     sa  = a.ToString(); if (a < 0)
                        {
                            sa = "(" + sa + ")";
                        }
                        string sb = b.ToString(); if (b < 0)
                        {
                            sb = "(" + sb + ")";
                        }
                        if (b < 0)
                        {
                            b = -b;
                        }
                        msg = String.Format("{0}*{1} + {2}*{3} = {4}", sa, x, sb, second, gcd);
                    }
                    catch (Exception ex)
                    {
                        msg = "-";
                    }

                    FireOnMessage(this, new PrimesBigInteger(x.ToString()), msg);
                }
            }
            catch (Exception ex)
            {
            }

            FireOnStop();
        }
示例#2
0
        // not used, public/private keys are input variables for this plugin
        private void generateKeys()
        {
            BigInteger twoPowModulusBits, n_plus1;

            p = BigIntegerHelper.RandomPrimeBits(keyBitLength - (keyBitLength / 2));
            q = BigIntegerHelper.RandomPrimeBits(keyBitLength / 2);
            n = p * q;

            // Just complete PK: n^2
            n_plus1  = n + 1;
            n_square = n * n;

            // compute lambda
            p_minus1 = p - 1;
            q_minus1 = q - 1;
            lambda   = BigIntegerHelper.LCM(p_minus1, q_minus1);

            // Compute n^(-1)
            twoPowModulusBits = 1 << keyBitLength;
            n_inv             = BigIntegerHelper.ModInverse(n, twoPowModulusBits);

            // Store the L(lambda)-part for decryption
            decDiv = BigInteger.ModPow(n + 1, lambda, n_square);
            decDiv = BigIntegerHelper.ModInverse(L(decDiv), n);

            p_square = p * p;
            q_square = q * q;

            hp = BigIntegerHelper.ModInverse((BigInteger.ModPow(n + 1, p_minus1, p_square) - 1) / p, p);
            hq = BigIntegerHelper.ModInverse((BigInteger.ModPow(n + 1, q_minus1, q_square) - 1) / q, q);

            // for CRT
            BigInteger s, t;

            BigIntegerHelper.ExtEuclid(p, q, out s, out t);
            ep = s * p;
            eq = t * q;

            // CRT Encryption:
            BigIntegerHelper.ExtEuclid(p_square, q_square, out s, out t);
            ep2 = s * p_square;
            eq2 = t * q_square;
        }