From 8a97534ff542f1ba6516a2164648b6a0a6094c3c Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Wed, 28 Nov 2018 10:25:24 +0100 Subject: [PATCH] Small fixes --- src/bigint.js | 43 ++++++++++++++++++++++++++++++++++++++++- src/calculateWitness.js | 2 +- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/bigint.js b/src/bigint.js index 75df0b4..cbb2c0f 100644 --- a/src/bigint.js +++ b/src/bigint.js @@ -169,12 +169,26 @@ if (typeof(BigInt) != "undefined") { return this & m; }; + wBigInt.prototype.div = function(c) { + return this / c; + }; + wBigInt.prototype.mod = function(c) { return this % c; }; wBigInt.prototype.modPow = function(e, m) { - return this ** e % m; + let acc = wBigInt.one; + let exp = this; + let rem = e; + while (rem) { + if (rem & wBigInt.one) { + acc = (acc * exp) %m; + } + exp = (exp * exp) % m; + rem = rem >> wBigInt.one; + } + return acc; }; wBigInt.prototype.greaterOrEquals = function(b) { @@ -218,6 +232,10 @@ if (typeof(BigInt) != "undefined") { wBigInt.zero = bigInt.zero; wBigInt.prototype = oldProto; + wBigInt.prototype.div = function(c) { + return this.divide(c); + }; + // Affine wBigInt.genAffine = (q) => { const nq = wBigInt.zero.minus(q); @@ -432,6 +450,29 @@ wBigInt.prototype.isZero = function (q) { return wBigInt.genIsZero(q)(this); }; +wBigInt.leBuff2int = function(buff) { + let res = wBigInt.zero; + for (let i=0; i