示例#1
0
        /// <summary>
        /// Умножить точку на число на эллиптической кривой
        /// </summary>
        /// <param name="value1">Точка на эллиптической кривой</param>
        /// <param name="value2">Множитель к точке</param>
        /// <returns></returns>
        public IEllipticCurvePoint Multiply(IntBig value2)
        {
            EllipticCurvePointB tempPoint = null;

            // Массив значений для этапа "предвычислений"
            // !!!!!!!!!!!!!!Занимательная задачка: надо подумать над графом вычислений, ибо почти стопроцентная уверенность, что не все значения массива понадобятся... Налицо оптимизация
            EllipticCurvePointB[] points = new EllipticCurvePointB[16];
            points[0]  = GetInfinity() as EllipticCurvePointB;
            points[1]  = this;
            points[2]  = points[1].Doubling() as EllipticCurvePointB;
            points[3]  = points[1].Addition(points[2]) as EllipticCurvePointB;
            points[4]  = points[2].Doubling() as EllipticCurvePointB;
            points[5]  = points[1].Addition(points[4]) as EllipticCurvePointB;
            points[6]  = points[3].Doubling() as EllipticCurvePointB;
            points[7]  = points[1].Addition(points[6]) as EllipticCurvePointB;
            points[8]  = points[4].Doubling() as EllipticCurvePointB;
            points[9]  = points[1].Addition(points[8]) as EllipticCurvePointB;
            points[10] = points[5].Doubling() as EllipticCurvePointB;
            points[11] = points[1].Addition(points[10]) as EllipticCurvePointB;
            points[12] = points[6].Doubling() as EllipticCurvePointB;
            points[13] = points[1].Addition(points[12]) as EllipticCurvePointB;
            points[14] = points[7].Doubling() as EllipticCurvePointB;
            points[15] = points[1].Addition(points[14]) as EllipticCurvePointB;
            // Начальный индекс множителя, от него начинается движение по двоичному представлению большого числа
            int index         = BigHelper.MaxNonZeroBitIndex(value2.m_Value);
            int howManyDouble = 0;
            int howMuchAdd    = 0;

            //if (index < 0)
            //    break;
            index     = GetWindow(value2, index, out howManyDouble, out howMuchAdd);
            tempPoint = points[howMuchAdd];

            while (true)
            {
                if (index < 0)
                {
                    break;
                }
                index = GetWindow(value2, index, out howManyDouble, out howMuchAdd);
                if (howManyDouble > 0)
                {
                    for (int t = 0; t < howManyDouble; ++t)
                    {
                        tempPoint = tempPoint.Doubling() as EllipticCurvePointB;
                    }
                }
                if (howMuchAdd > 0)
                {
                    tempPoint = tempPoint.Addition(points[howMuchAdd]) as EllipticCurvePointB;
                }
            }
            return(tempPoint);
        }
示例#2
0
 /// <summary>
 /// Удвоить точку на кривой
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static EllipticCurvePointB Doubling(EllipticCurvePointB value)
 {
     return(value.Doubling() as EllipticCurvePointB);
 }