GF2nPolynomial (Bouncy Castle Library 1.52 API Specification)

org.bouncycastle.pqc.math.linearalgebra

## Class GF2nPolynomial

- java.lang.Object
- - org.bouncycastle.pqc.math.linearalgebra.GF2nPolynomial

-     public class GF2nPolynomial
      extends java.lang.Object

  This class implements polynomials over GF2nElements.
  See Also:
    `GF2nElement`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GF2nPolynomial(GF2nPolynomial a)` Creates a new PolynomialGF2n by cloning the given PolynomialGF2n a.
    `GF2nPolynomial(GF2Polynomial polynomial, GF2nField B1)` Creates a new PolynomialGF2n from the given Bitstring polynomial over the GF2nField B1.
    `GF2nPolynomial(int deg, GF2nElement elem)` Creates a new PolynomialGF2n of size deg and elem as coefficients.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `GF2nPolynomial` | `add(GF2nPolynomial b)` Adds the PolynomialGF2n `b` to `this` and returns the result in a new `PolynomialGF2n`.
    `void` | `assignZeroToElements()`
    `GF2nElement` | `at(int index)` Returns the coefficient at index.
    `GF2nPolynomial[]` | `divide(GF2nPolynomial b)` Divides this by b and stores the result in a new PolynomialGF2n[2], quotient in result[0] and remainder in result[1].
    `void` | `enlarge(int k)` Enlarges the size of this PolynomialGF2n to k + 1.
    `boolean` | `equals(java.lang.Object other)`
    `GF2nPolynomial` | `gcd(GF2nPolynomial g)` Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.
    `int` | `getDegree()` Returns the degree of this PolynomialGF2n.
    `int` | `hashCode()`
    `boolean` | `isZero()` Returns true if all coefficients equal zero.
    `GF2nPolynomial` | `multiply(GF2nPolynomial b)` Multiplies this by b and returns the result in a new PolynomialGF2n.
    `GF2nPolynomial` | `multiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g)` Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.
    `GF2nPolynomial` | `quotient(GF2nPolynomial b)` Divides this by b and stores the quotient in a new PolynomialGF2n.
    `GF2nPolynomial` | `reduce(GF2nPolynomial g)` Reduces this by g and returns the result in a new PolynomialGF2n.
    `GF2nPolynomial` | `remainder(GF2nPolynomial b)` Divides this by b and stores the remainder in a new PolynomialGF2n.
    `GF2nPolynomial` | `scalarMultiply(GF2nElement s)` Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.
    `void` | `set(int index, GF2nElement elem)` Sets the coefficient at index to elem.
    `GF2nPolynomial` | `shiftLeft(int amount)`
    `void` | `shiftThisLeft(int amount)` Shifts left this by amount and stores the result in this PolynomialGF2n.
    `void` | `shrink()`
    `int` | `size()` Returns the size (=maximum degree + 1) of this PolynomialGF2n.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### GF2nPolynomial

          public GF2nPolynomial(int deg,
                        GF2nElement elem)

      Creates a new PolynomialGF2n of size deg and elem as coefficients.
      Parameters:
        `deg` - - the maximum degree + 1
        `elem` - - a GF2nElement

    - #### GF2nPolynomial

          public GF2nPolynomial(GF2nPolynomial a)

      Creates a new PolynomialGF2n by cloning the given PolynomialGF2n a.
      Parameters:
        `a` - the PolynomialGF2n to clone

    - #### GF2nPolynomial

          public GF2nPolynomial(GF2Polynomial polynomial,
                        GF2nField B1)

      Creates a new PolynomialGF2n from the given Bitstring polynomial over the GF2nField B1.
      Parameters:
        `polynomial` - the Bitstring to use
        `B1` - the field

  - ### Method Detail

    - #### assignZeroToElements

          public final void assignZeroToElements()

    - #### size

          public final int size()

      Returns the size (=maximum degree + 1) of this PolynomialGF2n. This is not the degree, use getDegree instead.
      Returns:
        the size (=maximum degree + 1) of this PolynomialGF2n.

    - #### getDegree

          public final int getDegree()

      Returns the degree of this PolynomialGF2n.
      Returns:
        the degree of this PolynomialGF2n.

    - #### enlarge

          public final void enlarge(int k)

      Enlarges the size of this PolynomialGF2n to k + 1.
      Parameters:
        `k` - the new maximum degree

    - #### shrink

          public final void shrink()

    - #### set

          public final void set(int index,
                 GF2nElement elem)

      Sets the coefficient at index to elem.
      Parameters:
        `index` - the index
        `elem` - the GF2nElement to store as coefficient index

    - #### at

          public final GF2nElement at(int index)

      Returns the coefficient at index.
      Parameters:
        `index` - the index
      Returns:
        the GF2nElement stored as coefficient index

    - #### isZero

          public final boolean isZero()

      Returns true if all coefficients equal zero.
      Returns:
        true if all coefficients equal zero.

    - #### equals

          public final boolean equals(java.lang.Object other)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        the hash code of this polynomial

    - #### add

          public final GF2nPolynomial add(GF2nPolynomial b)
                                   throws java.lang.RuntimeException

      Adds the PolynomialGF2n `b` to `this` and returns the result in a new `PolynomialGF2n`.
      Parameters:
        `b` - - the `PolynomialGF2n` to add
      Returns:
        `this + b`
      Throws:
        `DifferentFieldsException` - if `this` and `b` are not defined over the same field.
        `java.lang.RuntimeException`

    - #### scalarMultiply

          public final GF2nPolynomial scalarMultiply(GF2nElement s)
                                              throws java.lang.RuntimeException

      Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.
      Parameters:
        `s` - the scalar to multiply
      Returns:
        this x s
      Throws:
        `DifferentFieldsException` - if `this` and `s` are not defined over the same field.
        `java.lang.RuntimeException`

    - #### multiply

          public final GF2nPolynomial multiply(GF2nPolynomial b)
                                        throws java.lang.RuntimeException

      Multiplies this by b and returns the result in a new PolynomialGF2n.
      Parameters:
        `b` - the PolynomialGF2n to multiply
      Returns:
        this * b
      Throws:
        `DifferentFieldsException` - if `this` and `b` are not defined over the same field.
        `java.lang.RuntimeException`

    - #### multiplyAndReduce

          public final GF2nPolynomial multiplyAndReduce(GF2nPolynomial b,
                                         GF2nPolynomial g)
                                                 throws java.lang.RuntimeException,
                                                        java.lang.ArithmeticException

      Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.
      Parameters:
        `b` - the PolynomialGF2n to multiply
        `g` - the modul
      Returns:
        this * b mod g
      Throws:
        `DifferentFieldsException` - if `this`, `b` and `g` are not all defined over the same field.
        `java.lang.RuntimeException`
        `java.lang.ArithmeticException`

    - #### reduce

          public final GF2nPolynomial reduce(GF2nPolynomial g)
                                      throws java.lang.RuntimeException,
                                             java.lang.ArithmeticException

      Reduces this by g and returns the result in a new PolynomialGF2n.
      Parameters:
        `g` - - the modulus
      Returns:
        this % g
      Throws:
        `DifferentFieldsException` - if `this` and `g` are not defined over the same field.
        `java.lang.RuntimeException`
        `java.lang.ArithmeticException`

    - #### shiftThisLeft

          public final void shiftThisLeft(int amount)

      Shifts left this by amount and stores the result in this PolynomialGF2n.
      Parameters:
        `amount` - the amount to shift the coefficients

    - #### shiftLeft

          public final GF2nPolynomial shiftLeft(int amount)

    - #### divide

          public final GF2nPolynomial[] divide(GF2nPolynomial b)
                                        throws java.lang.RuntimeException,
                                               java.lang.ArithmeticException

      Divides this by b and stores the result in a new PolynomialGF2n[2], quotient in result[0] and remainder in result[1].
      Parameters:
        `b` - the divisor
      Returns:
        the quotient and remainder of this / b
      Throws:
        `DifferentFieldsException` - if `this` and `b` are not defined over the same field.
        `java.lang.RuntimeException`
        `java.lang.ArithmeticException`

    - #### remainder

          public final GF2nPolynomial remainder(GF2nPolynomial b)
                                         throws java.lang.RuntimeException,
                                                java.lang.ArithmeticException

      Divides this by b and stores the remainder in a new PolynomialGF2n.
      Parameters:
        `b` - the divisor
      Returns:
        the remainder this % b
      Throws:
        `DifferentFieldsException` - if `this` and `b` are not defined over the same field.
        `java.lang.RuntimeException`
        `java.lang.ArithmeticException`

    - #### quotient

          public final GF2nPolynomial quotient(GF2nPolynomial b)
                                        throws java.lang.RuntimeException,
                                               java.lang.ArithmeticException

      Divides this by b and stores the quotient in a new PolynomialGF2n.
      Parameters:
        `b` - the divisor
      Returns:
        the quotient this / b
      Throws:
        `DifferentFieldsException` - if `this` and `b` are not defined over the same field.
        `java.lang.RuntimeException`
        `java.lang.ArithmeticException`

    - #### gcd

          public final GF2nPolynomial gcd(GF2nPolynomial g)
                                   throws java.lang.RuntimeException,
                                          java.lang.ArithmeticException

      Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.
      Parameters:
        `g` - - a GF2nPolynomial
      Returns:
        gcd(this, g)
      Throws:
        `DifferentFieldsException` - if the coefficients of this and g use different fields
        `java.lang.ArithmeticException` - if coefficients are zero.
        `java.lang.RuntimeException`