Crates.io | finitelib |
lib.rs | finitelib |
version | |
source | src |
created_at | 2024-03-02 06:17:01.510003 |
updated_at | 2024-10-10 06:29:58.213124 |
description | A Rust library for advanced maths over finite groups, fields, their extensions, multi precision operations, euclidean rings, polynomials and related things. |
homepage | |
repository | https://github.com/fomalhaut88/finitelib |
max_upload_size | |
id | 1159520 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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:
GF(p)
, splitting - GF(p^m)
, binary - GF(2^m)
, Montgomery representation)Installation command:
cargo add finitelib
Or add this to your Cargo.toml
:
[dependencies]
finitelib = "0.1.7"
use finitelib::prelude::*;
use finitelib::gf::prime::Prime as GF;
// Define 256-bit unsigned integer type
type U256 = bigi_of_bits!(256);
// 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!(U256);
// Define a 256-bit prime number
let p = U256::from_decimal("67096435317933606252190858377894931905843553631817376158639971807689379094463");
// Define a finite field `GF(p)` with the prime characteristic `p`
let gf = GF::new(R256, p);
// Define two arbitrary numbers
let a = U256::from(3);
let b = U256::from(2);
// Perform division a / b inside the field
let c = gf.div(&a, &b).unwrap();
// Print the result as a decimal string
println!("{:?}", c.to_decimal());
// Perform multiplication
let d = gf.mul(&c, &b);
// Since multiplication is opposite to division `d` must be equal to `a`
assert_eq!(d, a);