Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

miller-rabin

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

miller-rabin - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

1.js

30

lib/mr.js

@@ -13,16 +13,20 @@ var bn = require('bn.js');

MillerRabin.prototype._rand = function _rand(n) {
MillerRabin.prototype._randbelow = function _randbelow(n) {
var len = n.bitLength();
var buf = this.rand.generate(Math.ceil(len / 8));
var min_bytes = Math.ceil(len / 8);
// Set low bits
buf[0] |= 3;
// Generage random bytes until a number less than n is found.
// This ensures that 0..n-1 have an equal probability of being selected.
do
var a = new bn(this.rand.generate(min_bytes));
while (a.cmp(n) >= 0);
// Mask high bits
var mask = len & 0x7;
if (mask !== 0)
buf[buf.length - 1] >>= 7 - mask;
return a;
};
return new bn(buf);
}
MillerRabin.prototype._randrange = function _randrange(start, stop) {
// Generate a random number greater than or equal to start and less than stop.
var size = stop.sub(start);
return start.add(this._randbelow(size));
};

@@ -39,3 +43,2 @@ MillerRabin.prototype.test = function test(n, k, cb) {

var n1 = n.subn(1);
var n2 = n1.subn(1);
for (var s = 0; !n1.testn(s); s++) {}

@@ -48,3 +51,3 @@ var d = n.shrn(s);

for (; k > 0; k--) {
var a = this._rand(n2);
var a = this._randrange(new bn(2), n1);
if (cb)

@@ -83,3 +86,2 @@ cb(a);

var n1 = n.subn(1);
var n2 = n1.subn(1);
for (var s = 0; !n1.testn(s); s++) {}

@@ -91,3 +93,3 @@ var d = n.shrn(s);

for (; k > 0; k--) {
var a = this._rand(n2);
var a = this._randrange(new bn(2), n1);

@@ -94,0 +96,0 @@ var g = n.gcd(a);

{
"name": "miller-rabin",
"version": "4.0.0",
"version": "4.0.1",
"description": "Miller Rabin algorithm for primality test",

@@ -5,0 +5,0 @@ "main": "lib/mr.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc