Struct finitefields::Finitefield[][src]

pub struct Finitefield {
    pub value: FF,
    pub modulo: FF,
}

Allows to perform simple algebraic operations over a finite field

Arguments

  • value - number be represented as value % modulo
  • modulo - An integer corresponding to the size of the modular space. For this to be a finite field it must be a prime number!

Examples

// Simple operations within a finite field

use finitefields::{FF,Finitefield,primes};

fn main(){
    // Pick a prime
    let modulo = primes::PRIMES31[0];
    // Define numbers to be cast into our field
    let num1: FF = 23742687;
    let num2: FF = 87129774;
       
    let fnum1 = Finitefield::new(num1, modulo).unwrap();
    let fnum2 = Finitefield::new(num2, modulo).unwrap();
     
    // Compute product
    let product = fnum1 * fnum2;
    assert_eq!(product.value, 174523906);

    // Compute the inverse of the product
    let product_inv = product.inverse().unwrap();
    assert_eq!(product_inv.value, 486606559);

    // Multiply by the product
    assert_eq!((product * product_inv).value, 1);
}

Fields

value: FFmodulo: FF

Implementations

impl Finitefield[src]

pub fn new(value: FF, modulo: FF) -> Result<Finitefield, &'static str>[src]

pub fn zero(modulo: FF) -> Finitefield[src]

pub fn one(modulo: FF) -> Finitefield[src]

pub fn is_zero(&self) -> bool[src]

pub fn update(&mut self, value: FF)[src]

pub fn mod_multiply(a: FF, b: FF, modulo: FF) -> FF[src]

Implementation of the multiplication of two positive integers a, b over a modulo. This multipication takes advantage of the x86 architecture, in particular is based on the way floats and integer discards overflowing digits.

TODO: check if this will still work for ARM architecture

pub fn egcd(&self, a: FF, b: FF) -> (FF, FF, FF)[src]

Extended Eucleadean Algorithm in terturn the GCD of two numbers a and b and two extra coefficients x and y:

gcd(a,b) = x * a + y * b

pub fn inverse(&self) -> Result<Finitefield, String>[src]

Compute the inverse by means of the Extended Eucleadean Algorithm

pub fn pow(&self, exp: usize) -> Finitefield[src]

Compute the exponent of the value over the finite field

Trait Implementations

impl Add<Finitefield> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the + operator.

impl Add<u64> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the + operator.

impl AddAssign<Finitefield> for Finitefield[src]

impl Clone for Finitefield[src]

impl Copy for Finitefield[src]

impl Debug for Finitefield[src]

impl Display for Finitefield[src]

impl Div<Finitefield> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the / operator.

impl Mul<Finitefield> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the * operator.

impl Mul<u64> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the * operator.

impl MulAssign<Finitefield> for Finitefield[src]

impl Neg for Finitefield[src]

type Output = Finitefield

The resulting type after applying the - operator.

impl Sub<Finitefield> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the - operator.

impl Sub<u64> for Finitefield[src]

type Output = Finitefield

The resulting type after applying the - operator.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.