I am learning about Hill Ciphe and need to find the inverse of the matrix to decrypt my ciphertext.
I googled and found some excellent material on matrices. They even let you download the source code of the entire program.
To test out the program , I wanted to input this matrix ( directly taken from Hill Cipher wiki)
and achieve the inverse of this matrix
I created a sample program which inputs the following matrix but the inverse of the matrix get very weird values like 0.158730 , -0.7777777
I dont think there is an issue with the source code of the program as the material is highly rated on codeproject. I dont understand why am i not getting the expected inverse matrix values as shown in the picture.
My sample code
You can download the full code here
package inverse;
public class Inverse {
public static void main(String[] args)
{
Matrix arr = new Matrix(3,3);
arr.setValueAt(0, 0, 6.0);
arr.setValueAt(0, 1, 24.0);
arr.setValueAt(0, 2, 1.0);
arr.setValueAt(1, 0, 13.0);
arr.setValueAt(1, 1, 16.0);
arr.setValueAt(1, 2, 10.0);
arr.setValueAt(2, 0, 20.0);
arr.setValueAt(2, 1, 17.0);
arr.setValueAt(2, 2, 15.0);
Matrix mat = new Matrix(3,3);
double determinant=0;
try
{
mat = MatrixMathematics.inverse(arr);
}
catch (NoSquareException e)
{
}
int x = 10;
}
}