Пример #1
0
        public static BigInteger2[] DivideBy(BigInteger2 Numb1, BigInteger2 Numb2)
        {
            var numb1 = BigInteger2.GetBytesTwosCompliment(Numb1);
            var numb2 = BigInteger2.GetBytesTwosCompliment(Numb2);

            BigInteger n1 = new BigInteger(numb1);
            BigInteger n2 = new BigInteger(numb2);
            BigInteger quot;
            BigInteger result = BigInteger.DivRem(n1, n2, out quot);

            BigInteger2[] results = new BigInteger2[2];

            var bitAry = BigInteger2.ReverseBigIntegerBitsToBitArray(result.ToByteArray());
            var whole  = new BigInteger2(bitAry.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry, whole, 0);

            var bitAry2  = BigInteger2.ReverseBigIntegerBitsToBitArray(quot.ToByteArray());
            var quotient = new BigInteger2(bitAry2.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry2, quotient, 0);

            results[0] = BigInteger2.NegateZeros(whole);
            results[1] = BigInteger2.NegateZeros(quotient);

            return(results);
        }
Пример #2
0
        public void setPrivateKey(byte[] key)
        {
            BitArray bitArray = new BitArray(key);

            d = new BigInteger2(bitArray.Length, 0);
            BigInteger2.CopyFromBitArrayFromIndex(bitArray, d, 0);
            d = BigInteger2.NegateZeros(d);
        }
Пример #3
0
        public void setPublicKey(byte[] key)
        {
            BitArray bitArray = new BitArray(key);

            e = new BigInteger2(bitArray.Length, 0);
            BigInteger2.CopyFromBitArrayFromIndex(bitArray, e, 0);
            e = BigInteger2.NegateZeros(e);
        }
Пример #4
0
        public void setModValue(byte[] value)
        {
            BitArray bitArray = new BitArray(value);

            Mod = new BigInteger2(bitArray.Length, 0);
            BigInteger2.CopyFromBitArrayFromIndex(bitArray, Mod, 0);
            Mod = BigInteger2.NegateZeros(Mod);
            n   = Mod.bitlength.Length - 2;
            //MessageBox.Show(""+(Mod.bitlength.Length - 2));
        }
Пример #5
0
        public static BigInteger2 gcd(BigInteger2 Numb1, BigInteger2 Numb2)
        {
            var numb1 = BigInteger2.GetBytesTwosCompliment(Numb1);
            var numb2 = BigInteger2.GetBytesTwosCompliment(Numb2);

            BigInteger n1 = new BigInteger(numb1);
            BigInteger n2 = new BigInteger(numb2);

            var result = BigInteger.GreatestCommonDivisor(n1, n2);

            var bitAry = BigInteger2.ReverseBigIntegerBitsToBitArray(result.ToByteArray());
            var whole  = new BigInteger2(bitAry.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry, whole, 0);
            return(BigInteger2.NegateZeros(whole));
        }
Пример #6
0
        public static BigInteger2 modPower(BigInteger2 current, BigInteger2 power, BigInteger2 mod)
        {
            var numb1 = BigInteger2.GetBytesTwosCompliment(current);
            var numb2 = BigInteger2.GetBytesTwosCompliment(power);
            var numb3 = BigInteger2.GetBytesTwosCompliment(mod);

            BigInteger n1 = new BigInteger(numb1);
            BigInteger n2 = new BigInteger(numb2);
            BigInteger n3 = new BigInteger(numb3);

            var result = BigInteger.ModPow(n1, n2, n3);

            var bitAry = BigInteger2.ReverseBigIntegerBitsToBitArray(result.ToByteArray());
            var whole  = new BigInteger2(bitAry.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry, whole, 0);

            return(BigInteger2.NegateZeros(whole));
        }