SparseTernaryPolynomial (Bouncy Castle Library 1.54 API Specification)
Date: 2015-12-29

org.bouncycastle.pqc.math.ntru.polynomial

## Class SparseTernaryPolynomial

- java.lang.Object
- - org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial

- All Implemented Interfaces:
    Polynomial, TernaryPolynomial

      public class SparseTernaryPolynomial
      extends java.lang.Object
      implements TernaryPolynomial

  A `TernaryPolynomial` with a "low" number of nonzero coefficients.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SparseTernaryPolynomial(int[] coeffs)` Constructs a new `SparseTernaryPolynomial` with a given set of coefficients.
    `SparseTernaryPolynomial(IntegerPolynomial intPoly)` Constructs a `DenseTernaryPolynomial` from a `IntegerPolynomial`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()`
    `boolean` | `equals(java.lang.Object obj)`
    `static SparseTernaryPolynomial` | `fromBinary(java.io.InputStream is, int N, int numOnes, int numNegOnes)` Decodes a byte array encoded with `toBinary()` to a ploynomial.
    `static SparseTernaryPolynomial` | `generateRandom(int N, int numOnes, int numNegOnes, java.security.SecureRandom random)` Generates a random polynomial with `numOnes` coefficients equal to 1, `numNegOnes` coefficients equal to -1, and the rest equal to 0.
    `int[]` | `getNegOnes()`
    `int[]` | `getOnes()`
    `int` | `hashCode()`
    `BigIntPolynomial` | `mult(BigIntPolynomial poly2)` Multiplies the polynomial by a `BigIntPolynomial`, taking the indices mod N.
    `IntegerPolynomial` | `mult(IntegerPolynomial poly2)` Multiplies the polynomial by an `IntegerPolynomial`, taking the indices mod N
    `IntegerPolynomial` | `mult(IntegerPolynomial poly2, int modulus)` Multiplies the polynomial by an `IntegerPolynomial`, taking the coefficient values mod `modulus` and the indices mod `N`.
    `int` | `size()` Returns the maximum number of coefficients the polynomial can have
    `byte[]` | `toBinary()` Encodes the polynomial to a byte array writing `BITS_PER_INDEX` bits for each coefficient.
    `IntegerPolynomial` | `toIntegerPolynomial()` Returns a polynomial that is equal to this polynomial (in the sense that `Polynomial.mult(IntegerPolynomial, int)` returns equal `IntegerPolynomial`s).

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

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

- - ### Constructor Detail

    - #### SparseTernaryPolynomial

          public SparseTernaryPolynomial(IntegerPolynomial intPoly)

      Constructs a `DenseTernaryPolynomial` from a `IntegerPolynomial`. The two polynomials are independent of each other.
      Parameters:
        `intPoly` - the original polynomial

    - #### SparseTernaryPolynomial

          public SparseTernaryPolynomial(int[] coeffs)

      Constructs a new `SparseTernaryPolynomial` with a given set of coefficients.
      Parameters:
        `coeffs` - the coefficients

  - ### Method Detail

    - #### fromBinary

          public static SparseTernaryPolynomial fromBinary(java.io.InputStream is,
                                           int N,
                                           int numOnes,
                                           int numNegOnes)
                                                    throws java.io.IOException

      Decodes a byte array encoded with `toBinary()` to a ploynomial.
      Parameters:
        `is` - an input stream containing an encoded polynomial
        `N` - number of coefficients including zeros
        `numOnes` - number of coefficients equal to 1
        `numNegOnes` - number of coefficients equal to -1
      Returns:
        the decoded polynomial
      Throws:
        `java.io.IOException`

    - #### generateRandom

          public static SparseTernaryPolynomial generateRandom(int N,
                                               int numOnes,
                                               int numNegOnes,
                                               java.security.SecureRandom random)

      Generates a random polynomial with `numOnes` coefficients equal to 1, `numNegOnes` coefficients equal to -1, and the rest equal to 0.
      Parameters:
        `N` - number of coefficients
        `numOnes` - number of 1's
        `numNegOnes` - number of -1's

    - #### mult

          public IntegerPolynomial mult(IntegerPolynomial poly2)

      Description copied from interface: `TernaryPolynomial`
      Multiplies the polynomial by an `IntegerPolynomial`, taking the indices mod N
      Specified by:
        `mult` in interface `Polynomial`
      Specified by:
        `mult` in interface `TernaryPolynomial`
      Parameters:
        `poly2` - a polynomial
      Returns:
        the product of the two polynomials

    - #### mult

          public IntegerPolynomial mult(IntegerPolynomial poly2,
                               int modulus)

      Description copied from interface: `Polynomial`
      Multiplies the polynomial by an `IntegerPolynomial`, taking the coefficient values mod `modulus` and the indices mod `N`.
      Specified by:
        `mult` in interface `Polynomial`
      Parameters:
        `poly2` - a polynomial
        `modulus` - a modulus to apply
      Returns:
        the product of the two polynomials

    - #### mult

          public BigIntPolynomial mult(BigIntPolynomial poly2)

      Description copied from interface: `Polynomial`
      Multiplies the polynomial by a `BigIntPolynomial`, taking the indices mod N. Does not change this polynomial but returns the result as a new polynomial.
      Both polynomials must have the same number of coefficients.
      Specified by:
        `mult` in interface `Polynomial`
      Parameters:
        `poly2` - the polynomial to multiply by
      Returns:
        a new polynomial

    - #### getOnes

          public int[] getOnes()

      Specified by:
        `getOnes` in interface `TernaryPolynomial`

    - #### getNegOnes

          public int[] getNegOnes()

      Specified by:
        `getNegOnes` in interface `TernaryPolynomial`

    - #### toBinary

          public byte[] toBinary()

      Encodes the polynomial to a byte array writing `BITS_PER_INDEX` bits for each coefficient.
      Returns:
        the encoded polynomial

    - #### toIntegerPolynomial

          public IntegerPolynomial toIntegerPolynomial()

      Description copied from interface: `Polynomial`
      Returns a polynomial that is equal to this polynomial (in the sense that `Polynomial.mult(IntegerPolynomial, int)` returns equal `IntegerPolynomial`s). The new polynomial is guaranteed to be independent of the original.
      Specified by:
        `toIntegerPolynomial` in interface `Polynomial`
      Returns:
        a new `IntegerPolynomial`.

    - #### size

          public int size()

      Description copied from interface: `TernaryPolynomial`
      Returns the maximum number of coefficients the polynomial can have
      Specified by:
        `size` in interface `TernaryPolynomial`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `TernaryPolynomial`

    - #### hashCode

          public int hashCode()

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

    - #### equals

          public boolean equals(java.lang.Object obj)

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