Class GF2Matrix
java.lang.Object
org.bouncycastle.pqc.legacy.math.linearalgebra.Matrix
org.bouncycastle.pqc.legacy.math.linearalgebra.GF2Matrix
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.legacy.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
ConstructorsConstructorDescriptionGF2Matrix
(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, 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.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionCompute the inverse of this matrix.Compute the transpose of this matrix.static GF2Matrix[]
Create a nxn random regular matrix and its inverse.boolean
Compare this matrix with another object.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.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[]
Returns encoded matrix, i.e., this matrix in byte array formdouble
Returns the percentage of the number of "ones" in this matrix.int[][]
Get the quadratic submatrix of this matrix consisting of the leftmost numRows columns.int
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.int
hashCode()
boolean
isZero()
Check if this is the zero matrix (i.e., all entries are zero).Compute the product of a permutation matrix (which is generated from an n-permutation) and this matrix.leftMultiply
(Vector vec) compute product a row vector and this matrixCompute the product of the matrix (this | Id) and a column vector, where Id is a (numRows x numRows) unit matrix.rightMultiply
(Matrix mat) Compute the product of this matrix and a matrix A over GF(2).Compute the product of this matrix and a permutation matrix which is generated from an n-permutation.rightMultiply
(Vector vec) Compute the product of this matrix and the given column vector.Compute the product of the matrix (Id | this) and a column vector, where Id is a (numRows x numRows) unit matrix.toString()
Methods inherited from class org.bouncycastle.pqc.legacy.math.linearalgebra.Matrix
getNumColumns, getNumRows
-
Constructor Details
-
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 (seeMatrix
for predefined constants)
-
GF2Matrix
Create an nxn matrix of the given type.- Parameters:
n
- the matrix sizetypeOfMatrix
- the matrix typesr
- the source of randomness
-
GF2Matrix
Copy constructor.- Parameters:
a
- anotherGF2Matrix
-
-
Method Details
-
createRandomRegularMatrixAndItsInverse
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:
getEncoded
in 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
Get the quadratic submatrix of this matrix consisting of the leftmost numRows columns.- Returns:
- the (numRows x numRows) submatrix
-
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
Get the submatrix of this matrix consisting of the rightmost numColumns-numRows columns.- Returns:
- the (numRows x (numColumns-numRows)) submatrix
-
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
Compute the transpose of this matrix.- Returns:
- (this)T
-
computeInverse
Compute the inverse of this matrix.- Specified by:
computeInverse
in classMatrix
- Returns:
- the inverse of this matrix (newly created).
- Throws:
ArithmeticException
- if this matrix is not invertible.
-
leftMultiply
Compute the product of a permutation matrix (which is generated from an n-permutation) and this matrix.- Parameters:
p
- the permutation- Returns:
GF2Matrix
P*this
-
leftMultiply
compute product a row vector and this matrix- Specified by:
leftMultiply
in classMatrix
- Parameters:
vec
- a vector over GF(2)- Returns:
- Vector product a*matrix
-
leftMultiplyLeftCompactForm
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
Compute the product of this matrix and a matrix A over GF(2).- Specified by:
rightMultiply
in classMatrix
- Parameters:
mat
- a matrix A over GF(2)- Returns:
- matrix product this*matrixA
-
rightMultiply
Compute the product of this matrix and a permutation matrix which is generated from an n-permutation.- Specified by:
rightMultiply
in classMatrix
- Parameters:
p
- the permutation- Returns:
GF2Matrix
this*P
-
rightMultiply
Compute the product of this matrix and the given column vector.- Specified by:
rightMultiply
in classMatrix
- Parameters:
vec
- the vector over GF(2)- Returns:
- this*vector
-
rightMultiplyRightCompactForm
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
Compare this matrix with another object. -
hashCode
public int hashCode() -
toString
-