Struct num_primes::Generator[][src]

pub struct Generator;
Expand description

Generator

This is the most commonly used struct. It is used to generate:

  • Large Unsigned Integers
  • Composite Numbers
  • Prime Numbers
  • Safe Primes
 
use num_primes::{Generator,Verification};
 
fn main(){
    let prime = Generator::new_prime(512);
    let _uint = Generator::new_uint(1024);
 
    // p = 2q + 1 || where p is safe prime
    let _safe_prime = Generator::safe_prime(64);
 
    let _ver: bool = Verification::is_prime(&prime);
}

Implementations

Generate Large Composite Numbers

This function guarantees the returned value is a composite number and is not prime.

use num_primes::Generator;
 
fn main(){
    // Generate Composite Number of 1024 bits
    let composite = Generator::new_composite(1024);
 
    // Print Out Composite Number
    println!("Composite Number: {}",composite);
}
Generate Large Unsigned Integer

This function takes an input (n) for the number of bits the unsigned integer should be

use num_primes::Generator;

fn main() {
    // Generate Large Random Unsigned Integer of 1024 bits
    let x = Generator::new_uint(1024);
 
    // Print Integer
    println!("Large Unsigned Integer: {}",x);
}
Generate Prime Number

This function generates a prime number of n-bits using three primality tests.

use num_primes::Generator;
 
fn main(){
    // Generate Two Primes (p,q) of 512 bits
    let p = Generator::new_prime(512);
    let q = Generator::new_prime(512);
 
    // Multiply p and q and return n
    let n = p * q;
 
    // Print n
    println!("n: {}",n);
}
Generate Safe Primes

This function will generate safe prime numbers, or numbers of the form p = 2q + 1 where p is the safe prime.

use num_primes::Generator;
 
fn main(){
    // p = 2q + 1 where p is the safe prime. This generates a number of 64 bits.
    let safe_prime = Generator::safe_prime(64);
}

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.