Exemplo n.º 1
0
        //supplementary methods
        private static double[,] CalculateInverseMatrix()
        {
            double[,] inverseMatrix = new double[3, 3];
            inverseMatrix[0, 0]     = (cryptoMatrix[1, 1] * cryptoMatrix[2, 2]) - (cryptoMatrix[1, 2] * cryptoMatrix[2, 1]);
            inverseMatrix[0, 1]     = (cryptoMatrix[1, 2] * cryptoMatrix[2, 0]) - (cryptoMatrix[1, 0] * cryptoMatrix[2, 2]);
            inverseMatrix[0, 2]     = (cryptoMatrix[1, 0] * cryptoMatrix[2, 1]) - (cryptoMatrix[1, 1] * cryptoMatrix[2, 0]);

            inverseMatrix[1, 0] = (cryptoMatrix[0, 2] * cryptoMatrix[2, 1]) - (cryptoMatrix[0, 1] * cryptoMatrix[2, 2]);
            inverseMatrix[1, 1] = (cryptoMatrix[0, 0] * cryptoMatrix[2, 2]) - (cryptoMatrix[0, 2] * cryptoMatrix[2, 0]);
            inverseMatrix[1, 2] = (cryptoMatrix[0, 1] * cryptoMatrix[2, 0]) - (cryptoMatrix[0, 0] * cryptoMatrix[2, 1]);

            inverseMatrix[2, 0] = (cryptoMatrix[0, 1] * cryptoMatrix[1, 2]) - (cryptoMatrix[0, 2] * cryptoMatrix[1, 1]);
            inverseMatrix[2, 1] = (cryptoMatrix[0, 2] * cryptoMatrix[1, 0]) - (cryptoMatrix[0, 0] * cryptoMatrix[1, 2]);
            inverseMatrix[2, 2] = (cryptoMatrix[0, 0] * cryptoMatrix[1, 1]) - (cryptoMatrix[0, 1] * cryptoMatrix[1, 0]);

            for (int i = 0; i < 3; i++)
            {
                for (int j = i + 1; j < 3; j++)
                {
                    Universal.Swap(ref inverseMatrix[i, j], ref inverseMatrix[j, i]);
                }
            }

            double m1          = cryptoMatrix[0, 0] * ((cryptoMatrix[1, 1] * cryptoMatrix[2, 2]) - (cryptoMatrix[1, 2] * cryptoMatrix[2, 1]));
            double m2          = cryptoMatrix[0, 1] * ((cryptoMatrix[1, 0] * cryptoMatrix[2, 2]) - (cryptoMatrix[1, 2] * cryptoMatrix[2, 0]));
            double m3          = cryptoMatrix[0, 2] * ((cryptoMatrix[1, 0] * cryptoMatrix[2, 1]) - (cryptoMatrix[1, 1] * cryptoMatrix[2, 0]));
            double determinant = m1 - m2 + m3;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    inverseMatrix[i, j] /= determinant;
                }
            }

            return(inverseMatrix);
        }