Class GF2nPolynomial
java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2nPolynomial
This class implements polynomials over GF2nElements.
- See Also:
-
Constructor Summary
ConstructorDescriptionGF2nPolynomial
(int deg, GF2nElement elem) Creates a new PolynomialGF2n of size deg and elem as coefficients.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
Modifier and TypeMethodDescriptionfinal GF2nPolynomial
Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.final void
final GF2nElement
at
(int index) Returns the coefficient at index.final GF2nPolynomial[]
Divides this by b and stores the result in a new PolynomialGF2n[2], quotient in result[0] and remainder in result[1].final void
enlarge
(int k) Enlarges the size of this PolynomialGF2n to k + 1.final boolean
final GF2nPolynomial
Computes the greatest common divisor of this and g and returns the result in a new PolynomialGF2n.final int
Returns the degree of this PolynomialGF2n.int
hashCode()
final boolean
isZero()
Returns true if all coefficients equal zero.final GF2nPolynomial
Multiplies this by b and returns the result in a new PolynomialGF2n.final GF2nPolynomial
Multiplies this by b, reduces the result by g and returns it in a new PolynomialGF2n.final GF2nPolynomial
Divides this by b and stores the quotient in a new PolynomialGF2n.final GF2nPolynomial
Reduces this by g and returns the result in a new PolynomialGF2n.final GF2nPolynomial
Divides this by b and stores the remainder in a new PolynomialGF2n.final GF2nPolynomial
Multiplies the scalar s to each coefficient of this PolynomialGF2n and returns the result in a new PolynomialGF2n.final void
set
(int index, GF2nElement elem) Sets the coefficient at index to elem.final GF2nPolynomial
shiftLeft
(int amount) final void
shiftThisLeft
(int amount) Shifts left this by amount and stores the result in this PolynomialGF2n.final void
shrink()
final int
size()
Returns the size (=maximum degree + 1) of this PolynomialGF2n.
-
Constructor Details
-
GF2nPolynomial
Creates a new PolynomialGF2n of size deg and elem as coefficients.- Parameters:
deg
- - the maximum degree + 1elem
- - a GF2nElement
-
GF2nPolynomial
Creates a new PolynomialGF2n by cloning the given PolynomialGF2n a.- Parameters:
a
- the PolynomialGF2n to clone
-
GF2nPolynomial
Creates a new PolynomialGF2n from the given Bitstring polynomial over the GF2nField B1.- Parameters:
polynomial
- the Bitstring to useB1
- the field
-
-
Method Details
-
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
Sets the coefficient at index to elem.- Parameters:
index
- the indexelem
- the GF2nElement to store as coefficient index
-
at
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
-
hashCode
public int hashCode() -
add
Adds the PolynomialGF2n b to this and returns the result in a new PolynomialGF2n.- Parameters:
b
- - the PolynomialGF2n to add- Returns:
- this + b
-
scalarMultiply
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
Multiplies this by b and returns the result in a new PolynomialGF2n.- Parameters:
b
- the PolynomialGF2n to multiply- Returns:
- this * b
-
multiplyAndReduce
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
Reduces this by g and returns the result in a new PolynomialGF2n.- Parameters:
g
- - the modulus- Returns:
- this % g
- Throws:
RuntimeException
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
-
divide
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 RuntimeException, ArithmeticException Divides this by b and stores the remainder in a new PolynomialGF2n.- Parameters:
b
- the divisor- Returns:
- the remainder this % b
- Throws:
RuntimeException
ArithmeticException
-
quotient
Divides this by b and stores the quotient in a new PolynomialGF2n.- Parameters:
b
- the divisor- Returns:
- the quotient this / b
- Throws:
RuntimeException
ArithmeticException
-
gcd
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)
-