Crates.io | finitefields |
lib.rs | finitefields |
version | 0.1.1 |
source | src |
created_at | 2021-03-24 16:15:13.285953 |
updated_at | 2021-03-26 15:22:10.902388 |
description | Perform algebraic operations between integers over a finite field |
homepage | |
repository | https://github.com/apelloni/finitefields |
max_upload_size | |
id | 372973 |
size | 91,096 |
Allows to perform simple algebraic operations over a finite field
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!// 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);
}