Beispiel #1
0
        public Point Multiply(Point p, BigInteger scalar)
        {
            if (scalar <= 0)
            {
                throw new Exception("Cannot multiply by a scalar which is <= 0");
            }
            if (p == Point.POINT_AT_INFINITY)
            {
                return(Point.POINT_AT_INFINITY);
            }

            Point p1       = new Point(p.X, p.Y);
            long  high_bit = scalar.HighestBit() - 1;

            // Double-and-add method
            while (high_bit >= 0)
            {
                p1 = Add(p1, p1); // Double
                if ((scalar.BitAt(high_bit)))
                {
                    p1 = Add(p1, p); // Add
                }
                --high_bit;
            }

            return(p1);
        }