1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/* ****************************************************************************
*
* Copyright 2013 Nedim Srndic
*
* This file is part of rsa - the RSA implementation in C++.
*
* PrimeGenerator.h
*
* A class used to generate large prime or random numbers.
*
* Author: Nedim Srndic
* Release date: 14th of March 2008
*
* ****************************************************************************
*/
#ifndef PRIMEGENERATOR_H_
#define PRIMEGENERATOR_H_
#include "coreSQLiteStudio_global.h"
#include "BigInt.h"
class API_EXPORT PrimeGenerator
{
private:
/* Generates a random "number" such as 1 <= "number" < "top".
* Returns it by reference in the "number" parameter. */
static void makeRandom( BigInt &number,
const BigInt &top);
/* Creates an odd BigInt with the specified number of digits.
* Returns it by reference in the "number" parameter. */
static void makePrimeCandidate( BigInt &number,
unsigned long int digitCount);
/* Tests the primality of the given _odd_ number using the
* Miller-Rabin probabilistic primality test. Returns true if
* the tested argument "number" is a probable prime with a
* probability of at least 1 - 4^(-k), otherwise false. */
static bool isProbablePrime(const BigInt &number,
unsigned long int k);
/* Returns true if "candidate" is a witness for the compositeness
* of "number", false if "candidate" is a strong liar. "exponent"
* and "squareCount" are used for computation */
static bool isWitness( BigInt candidate,
const BigInt &number,
const BigInt &exponent,
unsigned long int squareCount,
const BigInt &numberMinusOne);
public:
/* Generates a random number with digitCount digits.
* Returns it by reference in the "number" parameter. */
static void MakeRandom( BigInt &number,
unsigned long int digitCount);
/* Returns a probable prime number "digitCount" digits long,
* with a probability of at least 1 - 4^(-k) that it is prime. */
static BigInt Generate( unsigned long int digitCount,
unsigned long int k = 3);
};
#endif /*PRIMEGENERATOR_H_*/
|