How to use big-integer - 10 common examples

To help you get started, we’ve selected a few big-integer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iden3 / websnark / test / int.js View on Github external
it("It should profile int", async () => {

        const pA = pbInt.alloc();
        const pB = pbInt.alloc();
        const pC = pbInt.alloc(64);

        let start, end, time;

        const A = bigInt.one.shiftLeft(256).minus(1);
        const B = bigInt.one.shiftLeft(256).minus(1);

        pbInt.set(pA, A);
        pbInt.set(pB, B);

        start = new Date().getTime();
        pbInt.test_int_mul(pA, pB, pC, 50000000);
        end = new Date().getTime();
        time = end - start;

        const c1 = pbInt.get(pC, 1, 64);
        assert(c1.equals(A.times(B)));

        console.log("Mul Time (ms): " + time);

        // start = new Date().getTime();
        // pbInt.test_int_mulOld(pA, pB, pC, 50000000);
github iden3 / websnark / test / f1.js View on Github external
it("It should do various test in zq Snarks modules", async () => {
        const q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583");
        const f1 = await buildF1(q);
        const v= [
            q.minus(1),
            q.minus(2),
            q.minus(1).shiftRight(1),
            q.minus(1).shiftRight(1).add(1),
            q.minus(1).shiftRight(1).add(2),
            q.minus(1).shiftRight(1).minus(1),
            q.minus(1).shiftRight(1).minus(2),
            bigInt(2),
            bigInt.one,
            bigInt.zero
        ];

        const pA = f1.allocInt();
        const pB = f1.allocInt();
        const pC = f1.allocInt();
        let c;

        for (let i=0; i
github weijiekoh / zkmm / mastermind / src / test_mastermind.ts View on Github external
const genSalt = (): bigInt.BigInteger => {
    const buf = crypto.randomBytes(54)
    const salt = bigInt.fromArray(Array.from(buf), 256, false).minus(340)

    // 4 * (4^3) + 4 * (4^2) + 4 * (4^1) + 4 * (4^0) = 340
    // Only return values greater than the largest possible solution
    if (salt.lt(340)) {
        return genSalt()
    }

    return salt
}
github masx200 / webpack-react-vue-spa-awesome-config / src / 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架 / mypidashujisuan-bigint.js View on Github external
testname +
          "线程数为" +
          threadgeshu +
          " " +
          "圆周率计算" +
          piwei +
          "位 " +
          "计算圆周率中......" +
          "  \n"
      );
      //   debugger;
      //   console.log(outputtext1);
      console.log(testname);
      console.time(testname);
      strt = new Date().getTime();
      p = new bigInt(0);
      //   myworker = [];
      //   myworker.length = threadgeshu;
      finishflag = [];
      finishflag.length = threadgeshu;
      //   if (typeof worker1 == "undefined") {
      //     worker1 = new Worker("service-worker-mythread1-bigint.js");
      //   }
      // worker1=Array( threadgeshu)
      //   for (var i = 0, len = threadgeshu; i < len; i++) {
      //     myworker[i] = worker1;
      //   }
      //   var worker1 = Array(threadgeshu);
      //   myworker =Array(threadgeshu);
      //   for(var key=0;key< threadgeshu; key++){
      //       myworker[key]=undefined
      //   }
github masx200 / webpack-react-vue-spa-awesome-config / src / 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架 / mypidashujisuan-bigint.js View on Github external
arr[index].onmessage = function(event) {
              console.log(
                "主线程从副线程" + (index + 1) + "接收" + "event.data\n",
                event.data
              );
              // console.log(
              //   "第一个参数",
              //   event.data[0],
              //   "\n第二个参数",
              //   event.data[1]
              // );
              var p1 = new bigInt(event.data[0]);
              p = bigInt.add(p, p1);
              x = Math.max(x, parseInt(event.data[1]));
              finishflag[index] = 1;
              //   threadfinish(btnele);
              //   currentValue.terminate()
              rs(event.data);
            };
            arr[index].onerror = e => {
github masx200 / webpack-react-vue-spa-awesome-config / src / 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架 / mypidashujisuan-bigint.js View on Github external
arr[index].onmessage = function(event) {
              console.log(
                "主线程从副线程" + (index + 1) + "接收" + "event.data\n",
                event.data
              );
              // console.log(
              //   "第一个参数",
              //   event.data[0],
              //   "\n第二个参数",
              //   event.data[1]
              // );
              var p1 = new bigInt(event.data[0]);
              p = bigInt.add(p, p1);
              x = Math.max(x, parseInt(event.data[1]));
              finishflag[index] = 1;
              //   threadfinish(btnele);
              //   currentValue.terminate()
              rs(event.data);
            };
            arr[index].onerror = e => {
github DaoCasino / BankRollerApp / src / model / games.js View on Github external
confirmNumber_dice(input){
		/* Equivalent of solidity hash function:
			function confirm(bytes32 _s) public returns(uint256){
				return uint256 (sha3(_s));
			}
		*/
		let    hash    = '0x'+Eth.ABI.soliditySHA3(['bytes32'],[ input ]).toString('hex')
		let    confirm = bigInt(hash,16).divmod(65536).remainder.value
		return confirm
	}
	confirmNumber_blackjack(input){
github jeffijoe / snicket / src / subscriptions / all-subscription.ts View on Github external
async function getStartPositionForEnd() {
    try {
      const head = await store.readHeadPosition()
      // Edge case where start position is 0 (beginning of time) and the stream is empty.
      if (head === '0') {
        return BigInteger.zero
      }
      return BigInteger(head).plus(1)
    } catch (error) {
      logger.error(
        'Unable to get stream information. Dropping subscription and disposing.',
        error
      )
      await dropAndDispose()
      return BigInteger(-1)
    }
  }
github thetrime / proscript2 / src / arithmetic.js View on Github external
function toRationals(args) // Takes an array of Objects and returns an array of Rationals
{
    var r = new Array(args.length);
    for (var i = 0; i < args.length; i++)
    {
        var v = evaluate_expression(args[i]);
        if (v instanceof RationalTerm)
            r[i] = v.value;
        else if (v instanceof BigIntegerTerm)
            r[i] = new Rational(v.value, BigInteger.one);
        else if (v instanceof IntegerTerm)
            r[i] = new Rational(new BigInteger(v.value), BigInteger.one);
        else
            throw new Error("Illegal BigInteger conversion from " + v.getClass());
    }
    return r;
}
github jeffijoe / snicket / src / postgres / pg-stream-store.ts View on Github external
if (messages.length === count + 1) {
      // We intentionally included another message to see if we are at the end.
      // We are not.
      isEnd = false
      messages.splice(messages.length - 1, 1)
    }

    const lastMessage = messages[messages.length - 1]
    const nextPosition = forward
      ? BigInteger(lastMessage.position)
          .plus(BigInteger.one)
          .toString()
      : // nextVersion will be 0 at the end, but that always includes the first message in
        // the stream. There's no way around this that does not skip the first message.
        BigInteger.max(
          BigInteger(lastMessage.position).minus(BigInteger.one),
          BigInteger(-1)
        ).toString()

    return {
      isEnd,
      nextPosition,
      messages: await maybeFilterExpiredMessages(messages)
    }
  }