Class GF2Matrix
- java.lang.Object
 - 
- org.bouncycastle.pqc.math.linearalgebra.Matrix
 - 
- org.bouncycastle.pqc.math.linearalgebra.GF2Matrix
 
 
 
- 
public class GF2Matrix extends Matrix
This class describes some operations with matrices over finite field GF(2) and is used in ecc and MQ-PKC (also has some specific methods and implementation) 
- 
- 
Field Summary
- 
Fields inherited from class org.bouncycastle.pqc.math.linearalgebra.Matrix
MATRIX_TYPE_RANDOM_LT, MATRIX_TYPE_RANDOM_REGULAR, MATRIX_TYPE_RANDOM_UT, MATRIX_TYPE_UNIT, MATRIX_TYPE_ZERO, numColumns, numRows 
 - 
 
- 
Constructor Summary
Constructors Constructor Description GF2Matrix(byte[] enc)Create the matrix from encoded form.GF2Matrix(int n, char typeOfMatrix)Create an nxn matrix of the given type.GF2Matrix(int n, char typeOfMatrix, java.security.SecureRandom sr)Create an nxn matrix of the given type.GF2Matrix(int numColumns, int[][] matrix)Create the matrix with the contents of the given array.GF2Matrix(GF2Matrix a)Copy constructor. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MatrixcomputeInverse()Compute the inverse of this matrix.MatrixcomputeTranspose()Compute the transpose of this matrix.static GF2Matrix[]createRandomRegularMatrixAndItsInverse(int n, java.security.SecureRandom sr)Create a nxn random regular matrix and its inverse.booleanequals(java.lang.Object other)Compare this matrix with another object.GF2MatrixextendLeftCompactForm()Compute the full form matrix (this | Id) from this matrix in left compact form, where Id is the k x k identity matrix and k is the number of rows of this matrix.GF2MatrixextendRightCompactForm()Compute the full form matrix (Id | this) from this matrix in right compact form, where Id is the k x k identity matrix and k is the number of rows of this matrix.byte[]getEncoded()Returns encoded matrix, i.e., this matrix in byte array formdoublegetHammingWeight()Returns the percentage of the number of "ones" in this matrix.int[][]getIntArray()GF2MatrixgetLeftSubMatrix()Get the quadratic submatrix of this matrix consisting of the leftmost numRows columns.intgetLength()GF2MatrixgetRightSubMatrix()Get the submatrix of this matrix consisting of the rightmost numColumns-numRows columns.int[]getRow(int index)Return the row of this matrix with the given index.inthashCode()booleanisZero()Check if this is the zero matrix (i.e., all entries are zero).MatrixleftMultiply(Permutation p)Compute the product of a permutation matrix (which is generated from an n-permutation) and this matrix.VectorleftMultiply(Vector vec)compute product a row vector and this matrixVectorleftMultiplyLeftCompactForm(Vector vec)Compute the product of the matrix (this | Id) and a column vector, where Id is a (numRows x numRows) unit matrix.MatrixrightMultiply(Matrix mat)Compute the product of this matrix and a matrix A over GF(2).MatrixrightMultiply(Permutation p)Compute the product of this matrix and a permutation matrix which is generated from an n-permutation.VectorrightMultiply(Vector vec)Compute the product of this matrix and the given column vector.VectorrightMultiplyRightCompactForm(Vector vec)Compute the product of the matrix (Id | this) and a column vector, where Id is a (numRows x numRows) unit matrix.java.lang.StringtoString()- 
Methods inherited from class org.bouncycastle.pqc.math.linearalgebra.Matrix
getNumColumns, getNumRows 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
GF2Matrix
public GF2Matrix(byte[] enc)
Create the matrix from encoded form.- Parameters:
 enc- the encoded matrix
 
- 
GF2Matrix
public GF2Matrix(int numColumns, int[][] matrix)Create the matrix with the contents of the given array. The matrix is not copied. Unused coefficients are masked out.- Parameters:
 numColumns- the number of columnsmatrix- the element array
 
- 
GF2Matrix
public GF2Matrix(int n, char typeOfMatrix)Create an nxn matrix of the given type.- Parameters:
 n- the number of rows (and columns)typeOfMatrix- the martix type (seeMatrixfor predefined constants)
 
- 
GF2Matrix
public GF2Matrix(int n, char typeOfMatrix, java.security.SecureRandom sr)Create an nxn matrix of the given type.- Parameters:
 n- the matrix sizetypeOfMatrix- the matrix typesr- the source of randomness
 
 - 
 
- 
Method Detail
- 
createRandomRegularMatrixAndItsInverse
public static GF2Matrix[] createRandomRegularMatrixAndItsInverse(int n, java.security.SecureRandom sr)
Create a nxn random regular matrix and its inverse.- Parameters:
 n- number of rows (and columns)sr- source of randomness- Returns:
 - the created random regular matrix and its inverse
 
 
- 
getIntArray
public int[][] getIntArray()
- Returns:
 - the array keeping the matrix elements
 
 
- 
getLength
public int getLength()
- Returns:
 - the length of each array representing a row of this matrix
 
 
- 
getRow
public int[] getRow(int index)
Return the row of this matrix with the given index.- Parameters:
 index- the index- Returns:
 - the row of this matrix with the given index
 
 
- 
getEncoded
public byte[] getEncoded()
Returns encoded matrix, i.e., this matrix in byte array form- Specified by:
 getEncodedin classMatrix- Returns:
 - the encoded matrix
 
 
- 
getHammingWeight
public double getHammingWeight()
Returns the percentage of the number of "ones" in this matrix.- Returns:
 - the Hamming weight of this matrix (as a ratio).
 
 
- 
isZero
public boolean isZero()
Check if this is the zero matrix (i.e., all entries are zero). 
- 
getLeftSubMatrix
public GF2Matrix getLeftSubMatrix()
Get the quadratic submatrix of this matrix consisting of the leftmost numRows columns.- Returns:
 - the (numRows x numRows) submatrix
 
 
- 
extendLeftCompactForm
public GF2Matrix extendLeftCompactForm()
Compute the full form matrix (this | Id) from this matrix in left compact form, where Id is the k x k identity matrix and k is the number of rows of this matrix.- Returns:
 - (this | Id)
 
 
- 
getRightSubMatrix
public GF2Matrix getRightSubMatrix()
Get the submatrix of this matrix consisting of the rightmost numColumns-numRows columns.- Returns:
 - the (numRows x (numColumns-numRows)) submatrix
 
 
- 
extendRightCompactForm
public GF2Matrix extendRightCompactForm()
Compute the full form matrix (Id | this) from this matrix in right compact form, where Id is the k x k identity matrix and k is the number of rows of this matrix.- Returns:
 - (Id | this)
 
 
- 
computeTranspose
public Matrix computeTranspose()
Compute the transpose of this matrix.- Returns:
 - (this)T
 
 
- 
computeInverse
public Matrix computeInverse()
Compute the inverse of this matrix.- Specified by:
 computeInversein classMatrix- Returns:
 - the inverse of this matrix (newly created).
 - Throws:
 java.lang.ArithmeticException- if this matrix is not invertible.
 
- 
leftMultiply
public Matrix leftMultiply(Permutation p)
Compute the product of a permutation matrix (which is generated from an n-permutation) and this matrix.- Parameters:
 p- the permutation- Returns:
 GF2MatrixP*this
 
- 
leftMultiply
public Vector leftMultiply(Vector vec)
compute product a row vector and this matrix- Specified by:
 leftMultiplyin classMatrix- Parameters:
 vec- a vector over GF(2)- Returns:
 - Vector product a*matrix
 
 
- 
leftMultiplyLeftCompactForm
public Vector leftMultiplyLeftCompactForm(Vector vec)
Compute the product of the matrix (this | Id) and a column vector, where Id is a (numRows x numRows) unit matrix.- Parameters:
 vec- the vector over GF(2)- Returns:
 - (this | Id)*vector
 
 
- 
rightMultiply
public Matrix rightMultiply(Matrix mat)
Compute the product of this matrix and a matrix A over GF(2).- Specified by:
 rightMultiplyin classMatrix- Parameters:
 mat- a matrix A over GF(2)- Returns:
 - matrix product this*matrixA
 
 
- 
rightMultiply
public Matrix rightMultiply(Permutation p)
Compute the product of this matrix and a permutation matrix which is generated from an n-permutation.- Specified by:
 rightMultiplyin classMatrix- Parameters:
 p- the permutation- Returns:
 GF2Matrixthis*P
 
- 
rightMultiply
public Vector rightMultiply(Vector vec)
Compute the product of this matrix and the given column vector.- Specified by:
 rightMultiplyin classMatrix- Parameters:
 vec- the vector over GF(2)- Returns:
 - this*vector
 
 
- 
rightMultiplyRightCompactForm
public Vector rightMultiplyRightCompactForm(Vector vec)
Compute the product of the matrix (Id | this) and a column vector, where Id is a (numRows x numRows) unit matrix.- Parameters:
 vec- the vector over GF(2)- Returns:
 - (Id | this)*vector
 
 
- 
equals
public boolean equals(java.lang.Object other)
Compare this matrix with another object.- Overrides:
 equalsin classjava.lang.Object- Parameters:
 other- another object- Returns:
 - the result of the comparison
 
 
- 
hashCode
public int hashCode()
- Overrides:
 hashCodein classjava.lang.Object- Returns:
 - the hash code of this matrix
 
 
 - 
 
 -