The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::ProvablePrime - Generate a provable prime number, in pure Perl

SYNOPSIS

    #The returned prime will be 512 bits long
    #(i.e., the first and last bits will be 1)
    #and will be an instance of Math::BigInt.
    #
    my $prime = Math::ProvablePrime::find(512);

DISCUSSION

There’s not much more to say: this module returns a prime number of a specified bit length.

The specific algorithm is Maurer’s algorithm. The logic in this module is ported from a Python implementation first posted at http://s13.zetaboards.com/Crypto/topic/7234475/1/.

Note that cryptographic-strength randomness is not a necessity here because we’re making provable primes.

TODO

Make it faster. :)

Seriously, if there’s a faster algorithm for doing this, please let me know. The only limitation is that this module must be installable without a compiler. It will attempt to use the GMP or Pari backends for Math::BigInt if they are available.

LICENSE

This module is released under the same license as Perl.