0

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)

enter image description here

and achieve the inverse of this matrix

enter image description here

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

enter image description here

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;



    }

}
Computernerd
  • 7,378
  • 18
  • 66
  • 95
  • `"I dont think there is an issue with the source code of the program as the material is highly rated on codeproject."` -- I'm not sure that the volunteers on this site are in the best position to answer this, or to know whether your statement is true or not. The problem is either A) a problem with the source code you're using, B) a problem intrinsic to Java itself, or C) a problem with your understanding of the use of the source code or use of Java. When I've been in similar situations, 99.999% of the time my problem is a type (C) problem. I'm betting you're similar to me in this regard. – Hovercraft Full Of Eels Oct 19 '14 at 01:39
  • I get those "wierd" values as well. I certainly wouldn't have expected integers. What exactly do you understand by the inverse of a matrix? – Adrian May Oct 19 '14 at 01:49
  • My interpretation of "inverse of a matrix" is when I multiply the ciphertext with the "inverse of a matrix" , I get back the plaintext – Computernerd Oct 19 '14 at 01:54
  • I dunno what matrices have to do with encryption, but when you multiply any matrix by its inverse, in either order, you get the identity matrix. Try that with your "weird" and "expected" answers. – Adrian May Oct 19 '14 at 02:09

0 Answers0