finitelib
finitelib
is a library over advanced maths for finite groups, fields,
their extensions, multi precision operations and related things.
At the moment the library supports:
- Finite groups
- Finite fields (prime -
GF(p)
, splitting -GF(p^m)
, binary -GF(2^m)
, Montgomery representation) - Euclidean rings (including modular operations)
- Polynomials
- Multi precision operations over unsigned integers
- Converting
- Formatting
- Basic operations: addition, subtraction, product, division, bitwise operations
- Prime numbers: Fermat test, Miller-Rabin test, Legendre symbol, Tonelli–Shanks algorithm
Usage
Installation command:
cargo add finitelib
Or add this to your Cargo.toml
:
[]
= "0.1.8"
Basic example
use *;
use Prime as GF;
// Define 256-bit unsigned integer type
type U256 = bigi_of_bits!;
// Define an Euclidean ring over U256, that contains the correct basic
// math operations like addition, multiplication, Euclidean extended
// algorithm and so on.
let R256 = bigi_ring_for_bigi!;
// Define a 256-bit prime number
let p = U256 from_decimal;
// Define a finite field `GF(p)` with the prime characteristic `p`
let gf = GF new;
// Define two arbitrary numbers
let a = U256 from;
let b = U256 from;
// Perform division a / b inside the field
let c = gf.div.unwrap;
// Print the result as a decimal string
println!;
// Perform multiplication
let d = gf.mul;
// Since multiplication is opposite to division `d` must be equal to `a`
assert_eq!;