How to use the jsbn.BigInteger function in jsbn

To help you get started, we’ve selected a few jsbn 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 simbo1905 / thinbus-srp-npm / client.js View on Github external
SRP6JavascriptClientSession.prototype.fromHex = function(s) {
		"use strict";
		return new BigInteger(""+s, 16); // jdk1.7 rhino requires string concat
	};
	/* jshint ignore:end */
github gchq / CyberChef / src / core / operations / DateTime.js View on Github external
runFromFiletimeToUnix: function(input, args) {
        let units = args[0];
        input = new BigInteger(input).subtract(new BigInteger("116444736000000000"));
        if (units === "Seconds (s)"){
            input = input.divide(new BigInteger("10000000"));
        } else if (units === "Milliseconds (ms)") {
            input = input.divide(new BigInteger("10000"));
        } else if (units === "Microseconds (μs)") {
            input = input.divide(new BigInteger("10"));
        } else if (units === "Nanoseconds (ns)") {
            input = input.multiply(new BigInteger("100"));
        } else {
            throw "Unrecognised unit";
        }
        return input.toString();
    },
github gchq / CyberChef / src / core / operations / DateTime.js View on Github external
runToFiletimeFromUnix: function(input, args) {
        let units = args[0];
        input = new BigInteger(input);
        if (units === "Seconds (s)"){
            input = input.multiply(new BigInteger("10000000"));
        } else if (units === "Milliseconds (ms)") {
            input = input.multiply(new BigInteger("10000"));
        } else if (units === "Microseconds (μs)") {
            input = input.multiply(new BigInteger("10"));
        } else if (units === "Nanoseconds (ns)") {
            input = input.divide(new BigInteger("100"));
        } else {
            throw "Unrecognised unit";
        }
        return input.add(new BigInteger("116444736000000000")).toString();
    },
github Andyliwr / FE-learning-load / task08 / lidikang / styles / node_modules / sshpk / lib / utils.js View on Github external
'this source, the node jsbn lib is required.'));
	}

	var d = new bigInt(key.part.d.data);
	var buf;

	if (!key.part.dmodp) {
		var p = new bigInt(key.part.p.data);
		var dmodp = d.mod(p.subtract(1));

		buf = bigintToMpBuf(dmodp);
		key.part.dmodp = {name: 'dmodp', data: buf};
		key.parts.push(key.part.dmodp);
	}
	if (!key.part.dmodq) {
		var q = new bigInt(key.part.q.data);
		var dmodq = d.mod(q.subtract(1));

		buf = bigintToMpBuf(dmodq);
		key.part.dmodq = {name: 'dmodq', data: buf};
		key.parts.push(key.part.dmodq);
	}
}
github beaugunderson / ip-address / lib / ipv6.js View on Github external
Address6.prototype.possibleSubnets = function (optionalSubnetSize) {
  if (optionalSubnetSize === undefined) {
    optionalSubnetSize = 128;
  }

  var availableBits = constants6.BITS - this.subnetMask;
  var subnetBits = Math.abs(optionalSubnetSize - constants6.BITS);
  var subnetPowers = availableBits - subnetBits;

  if (subnetPowers < 0) {
    return '0';
  }

  return addCommas(new BigInteger('2', 10).pow(subnetPowers).toString(10));
};
github Andyliwr / FE-learning-load / task08 / lidikang / styles / node_modules / jodid25519 / lib / eddsa.js View on Github external
function _bi(value, base) {
        if (base !== undefined) {
            if (base === 256) {
                return _bi(utils.string2bytes(value));
            }
            return new BigInteger(value, base);
        } else if (typeof value === 'string') {
            return new BigInteger(value, 10);
        } else if ((value instanceof Array) || (value instanceof Uint8Array)
          || Buffer.isBuffer(value)) {
            return new BigInteger(value);
        } else if (typeof value === 'number') {
            return new BigInteger(value.toString(), 10);
        } else {
            throw "Can't convert " + value + " to BigInteger";
        }
    }
github beaugunderson / ip-address / lib / ipv6.js View on Github external
Address6.prototype.getBits = function (start, end) {
  return new BigInteger(this.getBitsBase2(start, end), 2);
};
github urbit / bridge / src / bridge / nockjs / bits.js View on Github external
function bytesToAtom(bytes) {
  var byt, parts = [];
  for ( var i = bytes.length - 1; i >= 0; --i ) {
    byt = bytes[i] & 0xff;
    parts.push(byt < 16 ? ("0" + byt.toString(16)) : byt.toString(16));
  }
  return new noun.Atom.Atom(new BigInteger(parts.join(''), 16));
}
github jen20 / pulumi-aws-vpc / nodejs / src / subnetDistributor.ts View on Github external
const BigInteger = require("jsbn").BigInteger;

    const ipv4 = new ipAddress.Address4(ipRange);
    if (!ipv4.isValid()) {
        throw new Error(`Invalid IP address range: ${ipRange}`);
    }

    const newSubnetMask = ipv4.subnetMask + newBits;
    if (newSubnetMask > 32) {
        throw new Error(`Requested ${newBits} new bits, but ` +
            `only ${32 - ipv4.subnetMask} are available.`);
    }

    const addressBI = ipv4.bigInteger();
    const newAddressBase = Math.pow(2, 32 - newSubnetMask);
    const netNumBI = new BigInteger(netNum.toString());

    const newAddressBI = addressBI.add(new BigInteger(newAddressBase.toString()).multiply(netNumBI));
    const newAddress = ipAddress.Address4.fromBigInteger(newAddressBI).address;

    return `${newAddress}/${newSubnetMask}`;
}
github jen20 / pulumi-aws-vpc / nodejs / src / subnetDistributor.ts View on Github external
const ipv4 = new ipAddress.Address4(ipRange);
    if (!ipv4.isValid()) {
        throw new Error(`Invalid IP address range: ${ipRange}`);
    }

    const newSubnetMask = ipv4.subnetMask + newBits;
    if (newSubnetMask > 32) {
        throw new Error(`Requested ${newBits} new bits, but ` +
            `only ${32 - ipv4.subnetMask} are available.`);
    }

    const addressBI = ipv4.bigInteger();
    const newAddressBase = Math.pow(2, 32 - newSubnetMask);
    const netNumBI = new BigInteger(netNum.toString());

    const newAddressBI = addressBI.add(new BigInteger(newAddressBase.toString()).multiply(netNumBI));
    const newAddress = ipAddress.Address4.fromBigInteger(newAddressBI).address;

    return `${newAddress}/${newSubnetMask}`;
}

jsbn

The jsbn library is a fast, portable implementation of large-number math in pure JavaScript, enabling public-key crypto and other applications on desktop and mobile browsers.

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis