Top Description Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.linearalgebra

public Class GF2Vector

extends Vector
Class Inheritance
Imports
java.security.SecureRandom, org.bouncycastle.util.Arrays

This class implements the abstract class Vector for the case of vectors over the finite field GF(2).
For the vector representation the array of type int[] is used, thus one element of the array holds 32 elements of the vector.
See Also
Vector

Field Summary

Modifier and TypeField and Description
private int[]
v

holds the elements of this vector

Inherited from org.bouncycastle.pqc.legacy.math.linearalgebra.Vector:
length

Constructor Summary

AccessConstructor and Description
public
GF2Vector(int
the length of the vector
length
)

Construct the zero vector of the given length.

public
GF2Vector(int
the length of the vector
length
,
SecureRandom
the source of randomness
sr
)

Construct a random GF2Vector of the given length.

public
GF2Vector(int
the length of the vector
length
,
int
the number of non-zero coefficients
t
,
SecureRandom
the source of randomness
sr
)

Construct a random GF2Vector of the given length with the specified number of non-zero coefficients.

public
GF2Vector(int
the length of the vector
length
,
int[]
the element array
v
)

Construct a GF2Vector of the given length and with elements from the given array.

public
GF2Vector(GF2Vector
another GF2Vector
other
)

Copy constructor.

protected
GF2Vector(int[]
the element array
v
,
int
the length of the vector
length
)

Construct a new GF2Vector of the given length and with the given element array.

Method Summary

Modifier and TypeMethod and Description
public Vector

Returns:

this + other
add
(Vector
another GF2Vector
other
)

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.add.

Adds another GF2Vector to this vector.

public boolean

Returns:

the result of the comparison
equals
(Object
vector
other
)

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.equals.

Check if the given object is equal to this vector.

public GF2Vector

Returns:

a new GF2Vector consisting of the first k elements of this vector
extractLeftVector
(int
the number of elements to extract
k
)

Return a new vector consisting of the first k elements of this vector.

public GF2Vector

Returns:

a new GF2Vector consisting of the last k elements of this vector
extractRightVector
(int
the number of elements to extract
k
)

Return a new vector consisting of the last k elements of this vector.

public GF2Vector

Returns:

the new GF2Vector [this_setJ[0], this_setJ[1], ..., this_setJ[#setJ-1]]
extractVector
(int[]
the set of indices of elements to extract
setJ
)

Return a new vector consisting of the elements of this vector with the indices given by the set setJ.

public int

Returns:

the value of the bit (0 or 1)
getBit
(int
the index
index
)

Return the value of the bit of this vector at the specified index.

public byte[]

Returns:

the encoded vector
getEncoded
()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.getEncoded.

Encode this vector as byte array.

public int

Returns:

the Hamming weight of this vector
getHammingWeight
()

Return the Hamming weight of this vector, i.e., compute the number of units of this vector.

public int[]

Returns:

the int array representation of this vector
getVecArray
()

public int

Returns:

the hash code of this vector
hashCode
()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

whether this is the zero vector (i.e., all elements are zero)
isZero
()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.isZero.

Return whether this is the zero vector (i.e., all elements are zero).

public Vector

Returns:

this*p = p*this
multiply
(Permutation
the permutation
p
)

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.multiply.

Multiply this vector with a permutation.

public static GF2Vector

Returns:

the decoded vector
OS2VP
(int
the length of the vector
length
,
byte[]
the encoded vector
encVec
)

Construct a new GF2Vector with the given length out of the encoded vector.

public void
setBit(int
the index of the coefficient to set
index
)

Set the coefficient at the given index to 1.

public GF2mVector

Returns:

the converted vector over GF(2m)
toExtensionFieldVector
(GF2mField
the finite field GF(2m)
field
)

Rewrite this vector as a vector over GF(2m) with t elements.

public String

Returns:

a human readable form of this vector
toString
()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.toString.

Returns a string representation of the object.

Inherited from org.bouncycastle.pqc.legacy.math.linearalgebra.Vector:
getLength

Field Detail

vback to summary
private int[] v

holds the elements of this vector

Constructor Detail

GF2Vectorback to summary
public GF2Vector(int length)

Construct the zero vector of the given length.

Parameters
length:int

the length of the vector

GF2Vectorback to summary
public GF2Vector(int length, SecureRandom sr)

Construct a random GF2Vector of the given length.

Parameters
length:int

the length of the vector

sr:SecureRandom

the source of randomness

GF2Vectorback to summary
public GF2Vector(int length, int t, SecureRandom sr)

Construct a random GF2Vector of the given length with the specified number of non-zero coefficients.

Parameters
length:int

the length of the vector

t:int

the number of non-zero coefficients

sr:SecureRandom

the source of randomness

GF2Vectorback to summary
public GF2Vector(int length, int[] v)

Construct a GF2Vector of the given length and with elements from the given array. The array is copied and unused bits are masked out.

Parameters
length:int

the length of the vector

v:int[]

the element array

GF2Vectorback to summary
public GF2Vector(GF2Vector other)

Copy constructor.

Parameters
other:GF2Vector

another GF2Vector

GF2Vectorback to summary
protected GF2Vector(int[] v, int length)

Construct a new GF2Vector of the given length and with the given element array. The array is not changed and only a reference to the array is stored. No length checking is performed either.

Parameters
v:int[]

the element array

length:int

the length of the vector

Method Detail

addback to summary
public Vector add(Vector other)

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.add.

Adds another GF2Vector to this vector.

Parameters
other:Vector

another GF2Vector

Returns:Vector

this + other

Exceptions
ArithmeticException:
if the other vector is not a GF2Vector or has another length.
equalsback to summary
public boolean equals(Object other)

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.equals.

Check if the given object is equal to this vector.

Parameters
other:Object

vector

Returns:boolean

the result of the comparison

extractLeftVectorback to summary
public GF2Vector extractLeftVector(int k)

Return a new vector consisting of the first k elements of this vector.

Parameters
k:int

the number of elements to extract

Returns:GF2Vector

a new GF2Vector consisting of the first k elements of this vector

extractRightVectorback to summary
public GF2Vector extractRightVector(int k)

Return a new vector consisting of the last k elements of this vector.

Parameters
k:int

the number of elements to extract

Returns:GF2Vector

a new GF2Vector consisting of the last k elements of this vector

extractVectorback to summary
public GF2Vector extractVector(int[] setJ)

Return a new vector consisting of the elements of this vector with the indices given by the set setJ.

Parameters
setJ:int[]

the set of indices of elements to extract

Returns:GF2Vector

the new GF2Vector [this_setJ[0], this_setJ[1], ..., this_setJ[#setJ-1]]

getBitback to summary
public int getBit(int index)

Return the value of the bit of this vector at the specified index.

Parameters
index:int

the index

Returns:int

the value of the bit (0 or 1)

getEncodedback to summary
public byte[] getEncoded()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.getEncoded.

Encode this vector as byte array.

Returns:byte[]

the encoded vector

getHammingWeightback to summary
public int getHammingWeight()

Return the Hamming weight of this vector, i.e., compute the number of units of this vector.

Returns:int

the Hamming weight of this vector

getVecArrayback to summary
public int[] getVecArray()
Returns:int[]

the int array representation of this vector

hashCodeback to summary
public int hashCode()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

the hash code of this vector

isZeroback to summary
public boolean isZero()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.isZero.

Doc from org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.isZero.

Return whether this is the zero vector (i.e., all elements are zero).

Returns:boolean

whether this is the zero vector (i.e., all elements are zero)

multiplyback to summary
public Vector multiply(Permutation p)

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.multiply.

Multiply this vector with a permutation.

Parameters
p:Permutation

the permutation

Returns:Vector

this*p = p*this

OS2VPback to summary
public static GF2Vector OS2VP(int length, byte[] encVec)

Construct a new GF2Vector with the given length out of the encoded vector.

Parameters
length:int

the length of the vector

encVec:byte[]

the encoded vector

Returns:GF2Vector

the decoded vector

setBitback to summary
public void setBit(int index)

Set the coefficient at the given index to 1. If the index is out of bounds, do nothing.

Parameters
index:int

the index of the coefficient to set

toExtensionFieldVectorback to summary
public GF2mVector toExtensionFieldVector(GF2mField field)

Rewrite this vector as a vector over GF(2m) with t elements.

Parameters
field:GF2mField

the finite field GF(2m)

Returns:GF2mVector

the converted vector over GF(2m)

toStringback to summary
public String toString()

Implements abstract org.bouncycastle.pqc.legacy.math.linearalgebra.Vector.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a human readable form of this vector