Class GF2nPolynomial
- java.lang.Object
 - 
- org.bouncycastle.pqc.math.linearalgebra.GF2nPolynomial
 
 
- 
public class GF2nPolynomial extends java.lang.ObjectThis class implements polynomials over GF2nElements.- See Also:
 GF2nElement
 
- 
- 
Constructor Summary
Constructors Constructor Description GF2nPolynomial(int deg, GF2nElement elem)Creates a new PolynomialGF2n of size deg and elem as coefficients.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. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GF2nPolynomialadd(GF2nPolynomial b)Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.voidassignZeroToElements()GF2nElementat(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].voidenlarge(int k)Enlarges the size of this PolynomialGF2n to k + 1.booleanequals(java.lang.Object other)GF2nPolynomialgcd(GF2nPolynomial g)Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.intgetDegree()Returns the degree of this PolynomialGF2n.inthashCode()booleanisZero()Returns true if all coefficients equal zero.GF2nPolynomialmultiply(GF2nPolynomial b)Multiplies this by b and returns the result in a new PolynomialGF2n.GF2nPolynomialmultiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g)Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.GF2nPolynomialquotient(GF2nPolynomial b)Divides this by b and stores the quotient in a new PolynomialGF2n.GF2nPolynomialreduce(GF2nPolynomial g)Reduces this by g and returns the result in a new PolynomialGF2n.GF2nPolynomialremainder(GF2nPolynomial b)Divides this by b and stores the remainder in a new PolynomialGF2n.GF2nPolynomialscalarMultiply(GF2nElement s)Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.voidset(int index, GF2nElement elem)Sets the coefficient at index to elem.GF2nPolynomialshiftLeft(int amount)voidshiftThisLeft(int amount)Shifts left this by amount and stores the result in this PolynomialGF2n.voidshrink()intsize()Returns the size (=maximum degree + 1) of this PolynomialGF2n. 
 - 
 
- 
- 
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 + 1elem- - 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 useB1- 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 indexelem- 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:
 equalsin classjava.lang.Object
 
- 
hashCode
public int hashCode()
- Overrides:
 hashCodein classjava.lang.Object- Returns:
 - the hash code of this polynomial
 
 
- 
add
public final GF2nPolynomial add(GF2nPolynomial b)
Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.- Parameters:
 b- - the PolynomialGF2n to add- Returns:
 - this + b
 
 
- 
scalarMultiply
public final GF2nPolynomial scalarMultiply(GF2nElement s)
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
 
 
- 
multiply
public final GF2nPolynomial multiply(GF2nPolynomial b)
Multiplies this by b and returns the result in a new PolynomialGF2n.- Parameters:
 b- the PolynomialGF2n to multiply- Returns:
 - this * b
 
 
- 
multiplyAndReduce
public final GF2nPolynomial multiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g)
Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.- Parameters:
 b- the PolynomialGF2n to multiplyg- the modul- Returns:
 - this * b mod g
 
 
- 
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:
 java.lang.RuntimeExceptionjava.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)
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
 
 
- 
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:
 java.lang.RuntimeExceptionjava.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:
 java.lang.RuntimeExceptionjava.lang.ArithmeticException
 
- 
gcd
public final GF2nPolynomial gcd(GF2nPolynomial g)
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)
 
 
 - 
 
 -