[−][src]Struct g2poly::G2Poly
Main type exported by this library
The polynomial is represented as the bits of the inner u64
. The least significant bit
represents c_0
in c_n * x^n + c_(n-1) * x^(n-1) + ... + c_0 * x^0
, the next bit c_1 and so on.
assert_eq!(format!("{}", G2Poly(0b101)), "G2Poly { x^2 + 1 }");
3 main operations +
, -
and
*
are implemented, as well as %
for remainder
calculation. Note that multiplication generates a G2PolyProd
so there is no risk of
overflow.
Division is left out as there is generally not needed for common use cases. This may change in a later release.
Methods
impl G2Poly
[src]
pub const UNIT: Self
[src]
The constant 1
polynomial.
This is the multiplicative identity. (a * UNIT = a)
pub const ZERO: Self
[src]
The constant 0 polynomial
This is the additive identity (a + ZERO = a)
pub const X: Self
[src]
The x
polynomial.
Useful for quickly generating x^n
values.
pub fn pow_mod(self, power: u64, modulus: G2Poly) -> G2Poly
[src]
Quickly calculate p^n mod m
Uses square-and-multiply to quickly exponentiate a polynomial.
Example
let p = G2Poly(0b1011); assert_eq!(p.pow_mod(127, G2Poly(0b1101)), G2Poly(0b110));
pub fn is_irreducible(self) -> bool
[src]
Determine if the given polynomial is irreducible.
Irreducible polynomials not be expressed as the product of other irreducible polynomials
(except 1
and itself). This uses Rabin's tests
to check if the given polynomial is irreducible.
Example
let p = G2Poly(0b101); assert!(!p.is_irreducible()); // x^2 + 1 == (x + 1)^2 in GF(2) let p = G2Poly(0b111); assert!(p.is_irreducible());
pub fn degree(self) -> Option<u64>
[src]
Get the degree of the polynomial
Returns None
for the 0 polynomial (which has degree -infinity
),
otherwise is guaranteed to return Some(d)
with d
the degree.
let z = G2Poly::ZERO; assert_eq!(z.degree(), None); let s = G2Poly(0b101); assert_eq!(s.degree(), Some(2));
pub fn is_generator(self, module: G2Poly) -> bool
[src]
Checks if a polynomial generates the multiplicative group mod m.
The field GF(2^p) can be interpreted as all polynomials of degree < p, with all operations
carried over from polynomials. Multiplication is done mod m, where m is some irreducible
polynomial of degree p. The multiplicative group is cyclic, so there is an element a
so
that all elements != can be expressed as a^n for some n < 2^p - 1.
This checks if the given polynomial is such a generator element mod m.
Example
let m = G2Poly(0b10011101); // The element `x` generates the whole group. assert!(G2Poly::X.is_generator(m));
Trait Implementations
impl Clone for G2Poly
[src]
fn clone(&self) -> G2Poly
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<G2Poly> for G2Poly
[src]
impl PartialOrd<G2Poly> for G2Poly
[src]
fn partial_cmp(&self, other: &G2Poly) -> Option<Ordering>
[src]
fn lt(&self, other: &G2Poly) -> bool
[src]
fn le(&self, other: &G2Poly) -> bool
[src]
fn gt(&self, other: &G2Poly) -> bool
[src]
fn ge(&self, other: &G2Poly) -> bool
[src]
impl Ord for G2Poly
[src]
fn cmp(&self, other: &G2Poly) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Returns max if self is greater than max, and min if self is less than min. Otherwise this will return self. Panics if min > max. Read more
impl Eq for G2Poly
[src]
impl Copy for G2Poly
[src]
impl Add<G2Poly> for G2Poly
[src]
type Output = G2Poly
The resulting type after applying the +
operator.
fn add(self, rhs: G2Poly) -> G2Poly
[src]
impl Sub<G2Poly> for G2Poly
[src]
type Output = G2Poly
The resulting type after applying the -
operator.
fn sub(self, rhs: G2Poly) -> G2Poly
[src]
impl Mul<G2Poly> for G2Poly
[src]
type Output = G2PolyProd
The resulting type after applying the *
operator.
fn mul(self, rhs: G2Poly) -> G2PolyProd
[src]
impl Rem<G2Poly> for G2Poly
[src]
type Output = G2Poly
The resulting type after applying the %
operator.
fn rem(self, rhs: G2Poly) -> G2Poly
[src]
impl Rem<G2Poly> for G2PolyProd
[src]
type Output = G2Poly
The resulting type after applying the %
operator.
fn rem(self, rhs: G2Poly) -> G2Poly
[src]
impl Debug for G2Poly
[src]
impl Display for G2Poly
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,