avt.DynamicFlashRotator.Net.RegCore.Cryptography.BigInteger.gcd C# (CSharp) Method

gcd() public method

public gcd ( BigInteger bi ) : BigInteger
bi BigInteger
return BigInteger
        public BigInteger gcd(BigInteger bi)
        {
            BigInteger x;
            BigInteger y;

            if ((data[maxLength - 1] & 0x80000000) != 0)     // negative
                x = -this;
            else
                x = this;

            if ((bi.data[maxLength - 1] & 0x80000000) != 0)     // negative
                y = -bi;
            else
                y = bi;

            BigInteger g = y;

            while (x.dataLength > 1 || (x.dataLength == 1 && x.data[0] != 0)) {
                g = x;
                x = y % x;
                y = g;
            }

            return g;
        }

Usage Example

コード例 #1
0
ファイル: BigInteger.cs プロジェクト: dnnsharp/DynamicRotator
        //***********************************************************************
        // Generates a random number with the specified number of bits such
        // that gcd(number, this) = 1
        //***********************************************************************

        public BigInteger genCoPrime(int bits, Random rand)
        {
            bool done = false;
            BigInteger result = new BigInteger();

            while (!done) {
                result.genRandomBits(bits, rand);
                //Console.WriteLine(result.ToString(16));

                // gcd test
                BigInteger g = result.gcd(this);
                if (g.dataLength == 1 && g.data[0] == 1)
                    done = true;
            }

            return result;
        }
All Usage Examples Of avt.DynamicFlashRotator.Net.RegCore.Cryptography.BigInteger::gcd