npm package for probabilistic primality test and probable prime generation based on Strengthening the Baillie-PSW primality test1.
npm i s-bpsw
import { isProbablePrime, probablePrime, nextProbablePrime } from 's-bpsw'
// or import all of the module's function
// import * as sbpsw from 's-bpsw'
// usage:
// console.log(sbpsw.isProbablePrime(17)) // True
console.log(isProbablePrime(2324632861)) // True
console.log(isProbablePrime(3616199781)) // False
Randomly generates a probable prime number of bitLength
.
Generates the smallest probable prime number greater than or equal to value
.
Generates the smallest prime number (next probable prime number) greater than or equal to a random number of bitLength
.
Generates a random number of bitLength
.
const random = rand(32) // 2881299645
console.log(isProbablePrime(random)) // False
prime = nextProbablePrime(random) // 2881299647
console.log(isProbablePrime(prime)) // True
Generates a probable safe prime from the smallest probable prime number greater than or equal to value
.
Generates a safe prime from a random number of bitLength
.
See LICENSE.
Footnotes
-
Robert Baillie, Andrew Fiori, and Samuel S Wagstaff Jr, Strengthening the Baillie-PSW primality test, Mathematics of Computation, Volume 90, Number 330, July 2021, pp. 1931--1955. Also available at https://arxiv.org/abs/2006.14425 . ↩