Пример #1
0
        public ECPoint Multiply(BigInteger b)
        {
            if (b.Sign == -1)
            {
                throw new FormatException("The multiplicator cannot be negative");
            }

            b = b % Secp256k1.N;
            BigInteger exp      = (b * 3) ^ b;
            ECPoint    result   = ECPoint.Infinity;
            ECPoint    affine   = this.Normalize();
            ECPoint    negative = affine.Negate();

            int        high = exp <= 0 ? 0 : (int)Math.Floor(BigInteger.Log(exp, 2));
            BigInteger bit  = BigInteger.One << high;

            for (int i = high; --i >= 0; bit >>= 1)
            {
                result = result.Twice();
                if (!(exp & bit).IsZero)
                {
                    result = result.Add(!(b & bit).IsZero ? negative : affine);
                }
            }

            result = result.Normalize();
            return(result);
        }
Пример #2
0
 public ECPoint Subtract(ECPoint b)
 {
     return(Add(b.Negate()));
 }
Пример #3
0
 public ECPoint Subtract(ECPoint b)
 {
     return Add(b.Negate());
 }