Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Arbitrary precision integral arithmetic for Node.js using OpenSSL.
This library is based on node-bigint by substack, but instead of using libgmp, it uses the builtin bignum functionality provided by OpenSSL. The advantage is that OpenSSL is already part of Node.js, so this library does not add any external dependency whatsoever.
When switching from node-bigint to node-bignum, please be aware of these differences:
10 / -3 = -3
, whereas bigint
rounds towards negative infinity, e.g. 10 / -3 = -4
.(Patches for the missing functionality are welcome.)
var bignum = require('bignum');
var b = bignum('782910138827292261791972728324982')
.sub('182373273283402171237474774728373')
.div(8)
;
console.log(b);
$ node simple.js
<Bignum 75067108192986261319312244199576>
Generate the perfect numbers:
// If 2**n-1 is prime, then (2**n-1) * 2**(n-1) is perfect.
var bignum = require('bignum');
for (var n = 0; n < 100; n++) {
var p = bignum.pow(2, n).sub(1);
if (p.probPrime(50)) {
var perfect = p.mul(bignum.pow(2, n - 1));
console.log(perfect.toString());
}
}
6
28
496
8128
33550336
8589869056
137438691328
2305843008139952128
2658455991569831744654692615953842176
191561942608236107294793378084303638130997321548169216
Create a new bignum
from n
and a base. n
can be a string, integer, or
another bignum
.
If you pass in a string you can set the base that string is encoded in.
Print out the bignum
instance in the requested base as a string.
Create a new bignum
from a Buffer
.
The default options are:
{
endian : 'big',
size : 1, // number of bytes in each word
}
Note that endian doesn't matter when size = 1. If you wish to reverse the entire buffer byte by byte, pass size: 'auto'.
For all of the instance methods below you can write either
bignum.method(x, y, z)
or if x is a bignum
instance``
x.method(y, z)
Turn a bignum
into a Number
. If the bignum
is too big you'll lose
precision or you'll get ±Infinity
.
Return a new Buffer
with the data from the bignum
.
The default options are:
{
endian : 'big',
size : 1, // number of bytes in each word
}
Note that endian doesn't matter when size = 1. If you wish to reverse the entire buffer byte by byte, pass size: 'auto'.
Return a new bignum
containing the instance value plus n
.
Return a new bignum
containing the instance value minus n
.
Return a new bignum
containing the instance value multiplied by n
.
Return a new bignum
containing the instance value integrally divided by n
.
Return a new bignum
with the absolute value of the instance.
Return a new bignum
with the negative of the instance value.
Compare the instance value to n
. Return a positive integer if > n
, a
negative integer if < n
, and 0 if == n
.
Return a boolean: whether the instance value is greater than n (> n
).
Return a boolean: whether the instance value is greater than or equal to n
(>= n
).
Return a boolean: whether the instance value is equal to n (== n
).
Return a boolean: whether the instance value is less than n (< n
).
Return a boolean: whether the instance value is less than or equal to n
(<= n
).
Return a new bignum
with the instance value bitwise AND (&)-ed with n
.
Return a new bignum
with the instance value bitwise inclusive-OR (|)-ed with
n
.
Return a new bignum
with the instance value bitwise exclusive-OR (^)-ed with
n
.
Return a new bignum
with the instance value modulo n
.
m
.
.pow(n)Return a new bignum
with the instance value raised to the n
th power.
Return a new bignum
with the instance value raised to the n
th power modulo
m
.
Compute the multiplicative inverse modulo m
.
If upperBound
is supplied, return a random bignum
between the instance value
and upperBound - 1
, inclusive.
Otherwise, return a random bignum
between 0 and the instance value - 1,
inclusive.
Return whether the bignum is:
using BN_is_prime_ex.
Return a new bignum
that is the square root. This truncates.
Return a new bignum
that is the nth
root. This truncates.
Return a new bignum
that is the 2^n
multiple. Equivalent of the <<
operator.
Return a new bignum
of the value integer divided by
2^n
. Equivalent of the >>
operator.
Return the greatest common divisor of the current bignum
with n
as a new
bignum
.
Return the number of bits used to represent the current bignum
.
To compile the package, your system needs to be set up for building Node.js modules.
You can install node-bignum with npm:
npm install bignum
You can clone the git repo and compile with
git clone git://github.com/justmoon/node-bignum.git
cd node-bignum
npm install
Run the tests with
npm test
FAQs
Arbitrary-precision integer arithmetic using OpenSSL
The npm package bignum receives a total of 1,725 weekly downloads. As such, bignum popularity was classified as popular.
We found that bignum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.