A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/youPickItUp/bn.js below:

youPickItUp/bn.js: BigNum in pure javascript

BigNum in pure javascript

npm install --save bn.js

const BN = require('bn.js');

var a = new BN('dead', 16);
var b = new BN('101010', 2);

var res = a.add(b);
console.log(res.toString(10));  // 57047

Note: decimals are not supported in this library.

My Open Source work is supported by Scout APM and other sponsors.

There are several prefixes to instructions that affect the way they work. Here is the list of them in the order of appearance in the function name:

Prefixes/postfixes are put in parens at the end of the line. endian - could be either le (little-endian) or be (big-endian).

When doing lots of reductions using the same modulo, it might be beneficial to use some tricks: like Montgomery multiplication, or using special algorithm for Mersenne Prime.

To enable this trick one should create a reduction context:

where num is just a BN instance.

Or:

var red = BN.red(primeName);

Where primeName is either of these Mersenne Primes:

Or:

To reduce numbers with Montgomery trick. .mont() is generally faster than .red(num), but slower than BN.red(primeName).

Before performing anything in reduction context - numbers should be converted to it. Usually, this means that one should:

Here is how one may convert numbers to red:

Where red is a reduction context created using instructions above

Here is how to convert them back:

Most of the instructions from the very start of this readme have their counterparts in red context:

Optimized for elliptic curves that work with 256-bit numbers. There is no limitation on the size of the numbers.

This software is licensed under the MIT License.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4