Struct Verification

Source
pub struct Verification;
Expand description

§Prime Verification

This struct is used to verify whether integers are prime, safe prime, or composite.

use num_primes::{Generator,Verification};
 
fn main(){
    let prime = Generator::new_prime(1024);
    let safe = Generator::safe_prime(128);
 
    let is_prime: bool = Verification::is_prime(&prime);
    let is_safe_prime: bool = Verification::is_safe_prime(&safe);
 
    assert_eq!(is_prime, true);
    assert_eq!(is_safe_prime, true);
}

Implementations§

Source§

impl Verification

Source

pub fn is_prime(n: &BigUint) -> bool

Examples found in repository?
examples/verification.rs (line 7)
3fn main(){
4    let prime = Generator::new_prime(1024);
5    let safe = Generator::safe_prime(128);
6
7    let is_prime: bool = Verification::is_prime(&prime);
8    let is_safe_prime: bool = Verification::is_safe_prime(&safe);
9
10    assert_eq!(is_prime, true);
11    assert_eq!(is_safe_prime, true);
12}
Source

pub fn is_composite(n: &BigUint) -> bool

Source

pub fn is_safe_prime(n: &BigUint) -> bool

Examples found in repository?
examples/verification.rs (line 8)
3fn main(){
4    let prime = Generator::new_prime(1024);
5    let safe = Generator::safe_prime(128);
6
7    let is_prime: bool = Verification::is_prime(&prime);
8    let is_safe_prime: bool = Verification::is_safe_prime(&safe);
9
10    assert_eq!(is_prime, true);
11    assert_eq!(is_safe_prime, true);
12}
Source

pub fn is_very_smooth_number(m: &BigUint, n: f64, c: u32) -> bool

§Very Smooth Number

This Function Is Deprecated And Should Rarely Be Used

use num_traits::FromPrimitive;
use num_bigint::BigUint;
use num_primes::Verification;
 
fn main(){
    // Set BigUint To 7
    let x: BigUint = BigUint::from_u64(7u64).unwrap();
 
    // Verify Its A Smooth Number
    let result: bool = Verification::is_smooth_number(&x,31.0,5);
 
    println!("Is A {} Smooth Number: {}",x,result);
}
Examples found in repository?
examples/vsn.rs (line 10)
5fn main() {
6    // Set BigUint To 7u64
7    let x: BigUint = BigUint::from_u64(7u64).unwrap();
8
9    // Verify Its A Smooth Number
10    let result: bool = Verification::is_very_smooth_number(&x,31.0,5);
11
12    println!("Is A {} Smooth Number: {}",x,result);
13}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.