s-bpsw

1.1.1 • Public • Published

Strengthened Baillie-PSW

npm package for probabilistic primality test and probable prime generation based on Strengthening the Baillie-PSW primality test1.

Installing

npm i s-bpsw

Importing (Node.js - ES6 or TypeScript)

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

Usage

isProbablePrime ( value )

console.log(isProbablePrime(2324632861)) // True
console.log(isProbablePrime(3616199781)) // False

probablePrime ( bitLength )

Randomly generates a probable prime number of bitLength.

nextProbablePrime ( value )

Generates the smallest probable prime number greater than or equal to value.

nextProbablePrimeBit ( bitLength )

Generates the smallest prime number (next probable prime number) greater than or equal to a random number of bitLength.

rand ( 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

safePrimeRandom ( value )

Generates a probable safe prime from the smallest probable prime number greater than or equal to value.

safePrimeBit ( bitLength )

Generates a safe prime from a random number of bitLength.

License

See LICENSE.

Author

  1. 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 .

Package Sidebar

Install

npm i s-bpsw

Weekly Downloads

5

Version

1.1.1

License

MIT

Unpacked Size

28.4 kB

Total Files

12

Last publish

Collaborators

  • harxki