Ejemplo n.º 1
0
        public static BigInteger InverseGf(this BigInteger value, BigInteger modulus)
        {
            BigInteger b = 1, c = 0, u = value, v = modulus;

            while (u.GetBitCount() > 1)
            {
                var j = u.GetBitCount() - v.GetBitCount();
                if (j < 0)
                {
                    (u, v) = (v, u);
                    (c, b) = (b, c);
                    j      = -j;
                }

                u = u.AddGf(v << j);
                b = b.AddGf(c << j);
            }

            return(b);
        }