Exemplo n.º 1
0
 public UInt64Division5(uint d)
 {
     Debug.Assert(d % 2 == 0);
     this.d    = d;
     this.dInv = IntegerMath.ModularInversePowerOfTwoModulus(d, 32);
     this.qmax = uint.MaxValue / d;
 }
            public Reducer(UInt32MontgomeryReduction reduction, uint modulus)
                : base(reduction, modulus)
            {
                if ((modulus & 1) == 0)
                {
                    throw new InvalidOperationException("not relatively prime");
                }
                var nInv = IntegerMath.ModularInversePowerOfTwoModulus(modulus, 32);

                k0 = IntegerMath.TwosComplement(nInv);
                var rModN = uint.MaxValue % modulus + 1;

                rSquaredModN = IntegerMath.ModularProduct(rModN, rModN, modulus);
            }
            public Reducer(UInt64MontgomeryReduction reduction, ulong modulus)
                : base(reduction, modulus)
            {
                if ((modulus & 1) == 0)
                {
                    throw new InvalidOperationException("not relatively prime");
                }
                int rLength   = modulus == (uint)modulus ? 32 : 64;
                var rMinusOne = rLength == 32 ? uint.MaxValue : ulong.MaxValue;
                var rModN     = rMinusOne % modulus + 1;

                rSquaredModN = IntegerMath.ModularProduct(rModN, rModN, modulus);
                var nInv = IntegerMath.ModularInversePowerOfTwoModulus(modulus, rLength);

                k0     = (uint)IntegerMath.TwosComplement(nInv);
                oneRep = 0;
            }