Struct finitefields::Finitefield [−][src]
Allows to perform simple algebraic operations over a finite field
Arguments
value
- number be represented asvalue % 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: FF
modulo: 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.
fn add(self, other: Finitefield) -> Finitefield
[src]
impl Add<u64> for Finitefield
[src]
type Output = Finitefield
The resulting type after applying the +
operator.
fn add(self, other: FF) -> Finitefield
[src]
impl AddAssign<Finitefield> for Finitefield
[src]
fn add_assign(&mut self, rhs: Finitefield)
[src]
impl Clone for Finitefield
[src]
fn clone(&self) -> Finitefield
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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.
fn div(self, other: Finitefield) -> Finitefield
[src]
impl Mul<Finitefield> for Finitefield
[src]
type Output = Finitefield
The resulting type after applying the *
operator.
fn mul(self, other: Finitefield) -> Finitefield
[src]
impl Mul<u64> for Finitefield
[src]
type Output = Finitefield
The resulting type after applying the *
operator.
fn mul(self, other: FF) -> Finitefield
[src]
impl MulAssign<Finitefield> for Finitefield
[src]
fn mul_assign(&mut self, rhs: Finitefield)
[src]
impl Neg for Finitefield
[src]
type Output = Finitefield
The resulting type after applying the -
operator.
fn neg(self) -> Finitefield
[src]
impl Sub<Finitefield> for Finitefield
[src]
type Output = Finitefield
The resulting type after applying the -
operator.
fn sub(self, other: Finitefield) -> Finitefield
[src]
impl Sub<u64> for Finitefield
[src]
type Output = Finitefield
The resulting type after applying the -
operator.
fn sub(self, other: FF) -> Finitefield
[src]
Auto Trait Implementations
impl RefUnwindSafe for Finitefield
impl Send for Finitefield
impl Sync for Finitefield
impl Unpin for Finitefield
impl UnwindSafe for Finitefield
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,