예제 #1
0
        private int Window(BigInt x, int i, int[] nbs, int[] nzs, int w)
        {
            // TODO Auto-generated method stub
            int j, r;

            nbs[0] = 1;
            nzs[0] = 0;
            sbyte[] xa = x.ToByteArray();

            //check for leading 0 bit
            if (!ByteArrayUtil.GetBitByDegree(i, xa))
            {
                return(0);
            }
            //adjust window if not enough bits left
            if (i - w + 1 < 0)
            {
                w = i + 1;
            }

            r = 1;
            for (j = i - 1; j > i - w; j--)
            {
                nbs[0]++;
                r *= 2;
                if (ByteArrayUtil.GetBitByDegree(j, xa))
                {
                    r += 1;
                }
                if (r % 4 == 0)
                {
                    r      /= 4;
                    nbs[0] -= 2;
                    nzs[0]  = 2;
                    break;
                }
            }

            if (r % 2 == 0)
            {
                r     /= 2;
                nzs[0] = 1;
                nbs[0]--;
            }
            return(r);
        }
예제 #2
0
        private Point SimpleMultiply(Point p, BigInt k)
        {
            if (!(this.field.IsValidElement(p.X)) || !(this.field.IsValidElement(p.Y))
                )
            {
                throw new ArgumentException("The input point must be taken over the field.");
            }

            if (p.IsInfinity())
            {
                return(p);
            }
            if (k.Equals(BigInt.ZERO))
            {
                return(Point.INFINITY);
            }
            if (k.Equals(BigInt.ONE))
            {
                return(p);
            }


            if (k.Signum() == -1)
            {
                k = k.Abs();
                p = this.Negate(p);
            }

            sbyte[] ba = k.ToByteArray();

            int degree = ByteArrayUtil.DegreeOf(ba) - 1;

            Point x = p;

            for (int i = degree; i >= 0; i--)
            {
                x = this.Dbl(x);
                if (ByteArrayUtil.GetBitByDegree(i, ba))
                {
                    x = this.Add(p, x);
                }
            }
            return(x);
        }