public class GF2Polynomial
extends java.lang.Object
GF2nPolynomialElement
,
GF2nField
Constructor and Description |
---|
GF2Polynomial(GF2Polynomial b)
Creates a new GF2Polynomial by cloneing the given GF2Polynomial b.
|
GF2Polynomial(int length)
Creates a new GF2Polynomial of the given length and value zero.
|
GF2Polynomial(int length,
java.math.BigInteger bi)
Creates a new GF2Polynomial by converting the given FlexiBigInt bi
according to 1363 and using the given length.
|
GF2Polynomial(int length,
byte[] os)
Creates a new GF2Polynomial by converting the given byte[] os
according to 1363 and using the given length.
|
GF2Polynomial(int length,
int[] bs)
Creates a new GF2Polynomial of the given length using the given
int[].
|
GF2Polynomial(int length,
java.util.Random rand)
Creates a new GF2Polynomial of the given length and random value.
|
GF2Polynomial(int length,
java.lang.String value)
Creates a new GF2Polynomial of the given length and value
selected by value:
ZERO
ONE
RANDOM
X
ALL
|
Modifier and Type | Method and Description |
---|---|
GF2Polynomial |
add(GF2Polynomial b)
Adds two GF2Polynomials, this and b, and returns the
result.
|
void |
addToThis(GF2Polynomial b)
Adds b to this GF2Polynomial and assigns the result to this
GF2Polynomial.
|
void |
assignAll()
Sets all Bits to 1.
|
void |
assignOne()
Sets the LSB to 1 and all other to 0, assigning 'one' to this
GF2Polynomial.
|
void |
assignX()
Sets Bit 1 to 1 and all other to 0, assigning 'x' to this GF2Polynomial.
|
void |
assignZero()
Resets all bits to zero.
|
java.lang.Object |
clone() |
GF2Polynomial[] |
divide(GF2Polynomial g)
Divides this by g and returns the quotient and remainder
in a new GF2Polynomial[2], quotient in [0], remainder in [1].
|
boolean |
equals(java.lang.Object other)
Returns true if two GF2Polynomials have the same size and value and thus
are equal.
|
void |
expandN(int i)
Expands len and int[] value to i.
|
GF2Polynomial |
gcd(GF2Polynomial g)
Returns the greatest common divisor of this and g in a
new GF2Polynomial.
|
int |
getBit(int i)
Returns the bit at position i.
|
int |
getLength()
Returns the length of this GF2Polynomial.
|
int |
hashCode() |
GF2Polynomial |
increase()
Toggles the LSB of this GF2Polynomial, increasing the value by 'one' and
returns the result in a new GF2Polynomial.
|
void |
increaseThis()
Toggles the LSB of this GF2Polynomial, increasing its value by 'one'.
|
boolean |
isIrreducible()
Checks if this is irreducible, according to IEEE P1363, A.5.5,
p103.
|
boolean |
isOne()
Tests if all bits are reset to 0 and LSB is set to 1.
|
boolean |
isZero()
Tests if all bits equal zero.
|
GF2Polynomial |
multiply(GF2Polynomial b)
Multiplies this GF2Polynomial with b and returns the result in a
new GF2Polynomial.
|
GF2Polynomial |
multiplyClassic(GF2Polynomial b)
Multiplies this GF2Polynomial with b and returns the result in a
new GF2Polynomial.
|
GF2Polynomial |
quotient(GF2Polynomial g)
Returns the absolute quotient of this divided by g in a
new GF2Polynomial.
|
void |
randomize()
Fills all len bits of this GF2Polynomial with random values.
|
void |
randomize(java.util.Random rand)
Fills all len bits of this GF2Polynomial with random values using the
specified source of randomness.
|
void |
reduceN()
Reduces len by finding the most significant bit set to one and reducing
len and blocks.
|
GF2Polynomial |
remainder(GF2Polynomial g)
Returns the remainder of this divided by g in a new
GF2Polynomial.
|
void |
resetBit(int i)
Resets the bit at position i.
|
void |
setBit(int i)
Sets the bit at position i.
|
GF2Polynomial |
shiftLeft()
Returns this GF2Polynomial shift-left by 1 in a new GF2Polynomial.
|
GF2Polynomial |
shiftLeft(int k)
Returns this GF2Polynomial shift-left by k in a new
GF2Polynomial.
|
void |
shiftLeftAddThis(GF2Polynomial b,
int k)
Shifts left b and adds the result to Its a fast version of
this = add(b.shl(k));
|
void |
shiftLeftThis()
Shifts-left this by one and enlarges the size of value if necesary.
|
GF2Polynomial |
shiftRight()
Returns this GF2Polynomial shift-right by 1 in a new GF2Polynomial.
|
void |
shiftRightThis()
Shifts-right this GF2Polynomial by 1.
|
void |
squareThisBitwise()
Squares this GF2Polynomial and expands it accordingly.
|
void |
squareThisPreCalc()
Squares this GF2Polynomial by using precomputed values of squaringTable.
|
GF2Polynomial |
subtract(GF2Polynomial b)
Subtracts two GF2Polynomials, this and b, and returns the
result in a new GF2Polynomial.
|
void |
subtractFromThis(GF2Polynomial b)
Subtracts b from this GF2Polynomial and assigns the result to
this GF2Polynomial.
|
boolean |
testBit(int i)
Tests the bit at position i.
|
byte[] |
toByteArray()
Converts this polynomial to a byte[] (octet string) according to 1363.
|
java.math.BigInteger |
toFlexiBigInt()
Converts this polynomial to an integer according to 1363.
|
int[] |
toIntegerArray()
Returns the value of this GF2Polynomial in an int[].
|
java.lang.String |
toString(int radix)
Returns a string representing this GF2Polynomials value using hexadecimal
or binary radix in MSB-first order.
|
boolean |
vectorMult(GF2Polynomial b)
Does a vector-multiplication modulo 2 and returns the result as boolean.
|
GF2Polynomial |
xor(GF2Polynomial b)
Returns the bitwise exclusive-or of this and b in a new
GF2Polynomial.
|
void |
xorBit(int i)
Xors the bit at position i.
|
void |
xorThisBy(GF2Polynomial b)
Computes the bitwise exclusive-or of this GF2Polynomial and b and
stores the result in this GF2Polynomial.
|
public GF2Polynomial(int length)
length
- the desired number of bits to storepublic GF2Polynomial(int length, java.util.Random rand)
length
- the desired number of bits to storerand
- SecureRandom to use for randomizationpublic GF2Polynomial(int length, java.lang.String value)
length
- the desired number of bits to storevalue
- the value described by a Stringpublic GF2Polynomial(int length, int[] bs)
length
- the desired number of bits to storebs
- contains the desired value, LSB in bs[0]public GF2Polynomial(int length, byte[] os)
length
- the intended length of this polynomialos
- the octet string to assign to this polynomialpublic GF2Polynomial(int length, java.math.BigInteger bi)
length
- the intended length of this polynomialbi
- the FlexiBigInt to assign to this polynomialpublic GF2Polynomial(GF2Polynomial b)
b
- the GF2Polynomial to clonepublic java.lang.Object clone()
clone
in class java.lang.Object
public int getLength()
public int[] toIntegerArray()
public java.lang.String toString(int radix)
radix
- the radix to use (2 or 16, otherwise 2 is used)public byte[] toByteArray()
public java.math.BigInteger toFlexiBigInt()
public void assignOne()
public void assignX()
public void assignAll()
public void assignZero()
public void randomize()
public void randomize(java.util.Random rand)
rand
- the source of randomnesspublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- the other GF2Polynomialpublic int hashCode()
hashCode
in class java.lang.Object
public boolean isZero()
public boolean isOne()
public void addToThis(GF2Polynomial b)
b
- GF2Polynomial to add to this GF2Polynomialpublic GF2Polynomial add(GF2Polynomial b)
b
- a GF2Polynomialpublic void subtractFromThis(GF2Polynomial b)
b
- a GF2Polynomialpublic GF2Polynomial subtract(GF2Polynomial b)
b
- a GF2Polynomialpublic void increaseThis()
public GF2Polynomial increase()
public GF2Polynomial multiplyClassic(GF2Polynomial b)
b
- a GF2Polynomialpublic GF2Polynomial multiply(GF2Polynomial b)
b
- a GF2Polynomialpublic GF2Polynomial remainder(GF2Polynomial g) throws java.lang.RuntimeException
g
- GF2Polynomial != 0java.lang.RuntimeException
public GF2Polynomial quotient(GF2Polynomial g) throws java.lang.RuntimeException
g
- GF2Polynomial != 0java.lang.RuntimeException
public GF2Polynomial[] divide(GF2Polynomial g) throws java.lang.RuntimeException
g
- GF2Polynomial != 0java.lang.RuntimeException
public GF2Polynomial gcd(GF2Polynomial g) throws java.lang.RuntimeException
g
- GF2Polynomial != 0java.lang.ArithmeticException
- if this and g both are equal to zerojava.lang.RuntimeException
public boolean isIrreducible()
public void reduceN()
public void expandN(int i)
i
- the intended lengthpublic void squareThisBitwise()
GF2nPolynomialElement.square()
public void squareThisPreCalc()
public boolean vectorMult(GF2Polynomial b) throws java.lang.RuntimeException
b
- GF2Polynomialjava.lang.RuntimeException
public GF2Polynomial xor(GF2Polynomial b)
b
- GF2Polynomialpublic void xorThisBy(GF2Polynomial b)
b
- GF2Polynomialpublic void setBit(int i) throws java.lang.RuntimeException
i
- intjava.lang.RuntimeException
- if (i < 0) || (i > (len - 1))public int getBit(int i)
i
- intpublic void resetBit(int i) throws java.lang.RuntimeException
i
- intjava.lang.RuntimeException
- if (i < 0) || (i > (len - 1))public void xorBit(int i) throws java.lang.RuntimeException
i
- intjava.lang.RuntimeException
- if (i < 0) || (i > (len - 1))public boolean testBit(int i)
i
- the position of the bit to be testedpublic GF2Polynomial shiftLeft()
public void shiftLeftThis()
public GF2Polynomial shiftLeft(int k)
k
- intpublic void shiftLeftAddThis(GF2Polynomial b, int k)
b
- GF2Polynomial to shift and add to thisk
- the amount to shiftGF2nPolynomialElement.invertEEA()
public GF2Polynomial shiftRight()
public void shiftRightThis()