Cryptography Reference
In-Depth Information
for (int k=1;k<=b.numCols;k++)
b.array[i][k]=BigIntegerMath.lnr(b.array[i][k].multiply(scalar),mat.modulus);
}
//Used by gaussianSolve to subtract one row from another
private void subtractRow(ModSquareMatrix mat,ModMatrix b,int i,int j) {
//Subtracts row j from row i; answer replaces row i
for (int k=1;k<=mat.numCols;k++)
mat.array[i][k]=BigIntegerMath.lnr(mat.array[i][k].subtract(mat.array[j][k]),mat.
modulus);
for (int k=1;k<=b.numCols;k++)
b.array[i][k]=BigIntegerMath.lnr(b.array[i][k].subtract(b.array[j][k]),mat.modulus)
;
}
//Used by gaussianSolve to swap two rows
private void swapRows(ModSquareMatrix mat,ModMatrix b,int r1,int r2) {
BigInteger temp;
for (int j=1;j<=mat.numCols;j++) {
temp=mat.array[r1][j];
mat.array[r1][j]=mat.array[r2][j];
mat.array[r2][j]=temp;
}
for (int j=1;j<=b.numCols;j++) {
temp=b.array[r1][j];
b.array[r1][j]=b.array[r2][j];
b.array[r2][j]=temp;
}
}
//Method produces an inverse of A (if possible) by using gaussianSolve on AX=I
//mod m
//where I is an identity matrix
public ModSquareMatrix inverse() throws
MatricesNonConformableException, SingularMatrixException {
//See the ModIdentityMatrix class-subclass of ModSquareMatrix
return gaussianSolve(new ModIdentityMatrix(numRows,modulus));
}
}
Finally, we define a ModIdentityMatrix class, which is a subclass of the ModSquare-
Matrix class. We use it in the inverse() method of ModMatrix, by generating the augmented
matrix A | I to produce an inverse of A .
import java.math.BigInteger;
//ModIdentityMatrix objects inherit all methods from ModSquareMatrix, and from
ModMatrix
Search WWH ::




Custom Search