Ejemplo n.º 1
0
        public BigIntegerPoint SummarizePoints(BigIntegerPoint first, BigIntegerPoint second)
        {
            if (first.X == 0 && first.Y == 0)
            {
                return(second);
            }

            if (first.X == 0 && second.Y == 0)
            {
                return(first);
            }

            if (first.X == second.X && (first.X == 0 || first.Y != second.Y))
            {
                return(new BigIntegerPoint(0, 0));
            }

            BigInteger numerator;
            BigInteger denominator;

            if (first.X != second.X)
            {
                numerator   = second.Y ^ first.Y;
                denominator = second.X ^ first.X;
            }
            else
            {
                numerator = PolynominalService.MultiplyPolynominal(first.X, first.X) ^
                            PolynominalService.MultiplyPolynominal(A, first.Y);
                denominator = PolynominalService.MultiplyPolynominal(first.X, A);
            }

            denominator = PolynominalService.InversePolynominal(denominator, Polynome);
            var k = PolynominalService.MultiplyPolynominal(numerator, denominator);

            k = PolynominalService.ModPolynominal(k, Polynome);

            var x = PolynominalService.MultiplyPolynominal(k, k);

            x ^= PolynominalService.MultiplyPolynominal(A, k);
            x ^= B;
            if (first.X != second.X)
            {
                x ^= first.X;
                x ^= second.X;
            }
            x = PolynominalService.ModPolynominal(x, Polynome);

            var y = x ^ first.X;

            y  = PolynominalService.MultiplyPolynominal(y, k);
            y ^= first.Y;
            y ^= PolynominalService.MultiplyPolynominal(A, x);
            y  = PolynominalService.ModPolynominal(y, Polynome);

            return(new BigIntegerPoint(x, y));
        }
        public BigIntegerPoint MultiplyPointByNumber(BigIntegerPoint point, BigInteger number)
        {
            var newPoint     = new BigIntegerPoint(point.X, point.Y);
            var binaryNumber = number.ToBinaryString();

            foreach (var bit in binaryNumber.Substring(2))
            {
                newPoint = SummarizePoints(newPoint, newPoint);
                if (bit == '1')
                {
                    newPoint = SummarizePoints(newPoint, point);
                }
            }

            return(newPoint);
        }
        public BigIntegerPoint SummarizePoints(BigIntegerPoint first, BigIntegerPoint second)
        {
            if (first.X == second.X && first.Y == second.Y)
            {
                return(new BigIntegerPoint(0, 0));
            }

            BigInteger numerator;
            BigInteger denominator;

            if (first.X != second.X)
            {
                numerator   = second.Y ^ first.Y;
                denominator = second.X ^ first.X;
            }
            else
            {
                numerator   = PolynominalService.MultiplyPolynominal(first.X, second.X);
                numerator  ^= B;
                denominator = A;
            }

            denominator = PolynominalService.InversePolynominal(denominator, Polynome);
            var k = PolynominalService.MultiplyPolynominal(numerator, denominator);

            k = PolynominalService.ModPolynominal(k, Polynome);

            var x = PolynominalService.MultiplyPolynominal(k, k);

            if (first.X != second.X)
            {
                x ^= first.X;
                x ^= second.X;
            }
            x = PolynominalService.ModPolynominal(x, Polynome);

            var y = first.X ^ x;

            y  = PolynominalService.MultiplyPolynominal(y, k);
            y ^= first.Y;
            y ^= A;
            y  = PolynominalService.ModPolynominal(y, Polynome);

            return(new BigIntegerPoint(x, y));
        }
Ejemplo n.º 4
0
        public BigIntegerPoint SummarizePoints(BigIntegerPoint first, BigIntegerPoint second)
        {
            BigInteger k = 0;

            if (first.X != second.X)
            {
                k = (second.Y - first.Y) * MulInv(second.X - first.X, P);
            }
            else
            {
                k = (3 * first.X * first.X + A) * MulInv(2 * first.Y, P);
            }

            var d    = first.Y - k * first.X;
            var newX = k * k - first.X - second.X;

            return(new BigIntegerPoint(newX.Mod(P), (-(k * newX + d)).Mod(P)));
        }