Пример #1
0
        private static MyPoint Add(MyPoint leftOperand, MyPoint rightOperand)
        {
            if (leftOperand.IsInfinite)
            {
                return(rightOperand);
            }
            if (rightOperand.IsInfinite)
            {
                return(leftOperand);
            }

            var curve  = leftOperand.Curve;
            var lambda = GetLambdaForAddition(leftOperand, rightOperand) % curve.Prime;
            var newX   = (lambda ^ 2) - leftOperand.X - rightOperand.X;

            newX = newX % curve.Prime;
            var newY = lambda * (leftOperand.X - newX) - leftOperand.Y;

            newY = newY % curve.Prime;

            var newPoint = new MyPoint(newX, newY, curve);

            newPoint.IsOnCurve();
            return(newPoint);
        }
Пример #2
0
        public MyPoint Negate()
        {
            var point = new MyPoint(X, Y.Negate(), Curve);

            point.IsOnCurve();
            return(point);
        }
Пример #3
0
        private MyPoint Double()
        {
            if (IsInfinite)
            {
                return(this);
            }

            var lambda = GetLambdaForDoubling() % Curve.Prime;
            var newX   = (lambda ^ 2) - X * 2;

            newX = newX % Curve.Prime;
            var newY = (lambda * (X - newX)) - Y;

            newY = newY % Curve.Prime;

            var newPoint = new MyPoint(newX, newY, Curve);

            newPoint.IsOnCurve();
            return(newPoint);
        }