Class ComputeInField


  • public class ComputeInField
    extends java.lang.Object
    This class offers different operations on matrices in field GF2^8.

    Implemented are functions: - finding inverse of a matrix - solving linear equation systems using the Gauss-Elimination method - basic operations like matrix multiplication, addition and so on.

    • Constructor Summary

      Constructors 
      Constructor Description
      ComputeInField()
      Constructor with no parameters
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      short[][] addSquareMatrix​(short[][] matrix1, short[][] matrix2)
      Adds the n x n matrices matrix1 and matrix2
      short[] addVect​(short[] vector1, short[] vector2)
      Addition of two vectors
      short[][] inverse​(short[][] coef)
      This function computes the inverse of a given matrix using the Gauss- Elimination method.
      short[] multiplyMatrix​(short[][] M1, short[] m)
      This function multiplies a given matrix with a one-dimensional array.
      short[][] multiplyMatrix​(short[][] M1, short[][] M2)
      This function multiplies two given matrices.
      short[][] multMatrix​(short scalar, short[][] matrix)
      Multiplies matrix with scalar
      short[] multVect​(short scalar, short[] vector)
      Multiplies vector with scalar
      short[][] multVects​(short[] vector1, short[] vector2)
      Multiplication of column vector with row vector
      short[] solveEquation​(short[][] B, short[] b)
      This function finds a solution of the equation Bx = b.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ComputeInField

        public ComputeInField()
        Constructor with no parameters
    • Method Detail

      • solveEquation

        public short[] solveEquation​(short[][] B,
                                     short[] b)
        This function finds a solution of the equation Bx = b. Exception is thrown if the linear equation system has no solution
        Parameters:
        B - this matrix is the left part of the equation (B in the equation above)
        b - the right part of the equation (b in the equation above)
        Returns:
        x the solution of the equation if it is solvable null otherwise
        Throws:
        java.lang.RuntimeException - if LES is not solvable
      • inverse

        public short[][] inverse​(short[][] coef)
        This function computes the inverse of a given matrix using the Gauss- Elimination method.

        An exception is thrown if the matrix has no inverse

        Parameters:
        coef - the matrix which inverse matrix is needed
        Returns:
        inverse matrix of the input matrix. If the matrix is singular, null is returned.
        Throws:
        java.lang.RuntimeException - if the given matrix is not invertible
      • multiplyMatrix

        public short[][] multiplyMatrix​(short[][] M1,
                                        short[][] M2)
                                 throws java.lang.RuntimeException
        This function multiplies two given matrices. If the given matrices cannot be multiplied due to different sizes, an exception is thrown.
        Parameters:
        M1 - -the 1st matrix
        M2 - -the 2nd matrix
        Returns:
        A = M1*M2
        Throws:
        java.lang.RuntimeException - in case the given matrices cannot be multiplied due to different dimensions.
      • multiplyMatrix

        public short[] multiplyMatrix​(short[][] M1,
                                      short[] m)
                               throws java.lang.RuntimeException
        This function multiplies a given matrix with a one-dimensional array.

        An exception is thrown, if the number of columns in the matrix and the number of rows in the one-dim. array differ.

        Parameters:
        M1 - the matrix to be multiplied
        m - the one-dimensional array to be multiplied
        Returns:
        M1*m
        Throws:
        java.lang.RuntimeException - in case of dimension inconsistency
      • addVect

        public short[] addVect​(short[] vector1,
                               short[] vector2)
        Addition of two vectors
        Parameters:
        vector1 - first summand, always of dim n
        vector2 - second summand, always of dim n
        Returns:
        addition of vector1 and vector2
        Throws:
        java.lang.RuntimeException - in case the addition is impossible due to inconsistency in the dimensions
      • multVects

        public short[][] multVects​(short[] vector1,
                                   short[] vector2)
        Multiplication of column vector with row vector
        Parameters:
        vector1 - column vector, always n x 1
        vector2 - row vector, always 1 x n
        Returns:
        resulting n x n matrix of multiplication
        Throws:
        java.lang.RuntimeException - in case the multiplication is impossible due to inconsistency in the dimensions
      • multVect

        public short[] multVect​(short scalar,
                                short[] vector)
        Multiplies vector with scalar
        Parameters:
        scalar - galois element to multiply vector with
        vector - vector to be multiplied
        Returns:
        vector multiplied with scalar
      • multMatrix

        public short[][] multMatrix​(short scalar,
                                    short[][] matrix)
        Multiplies matrix with scalar
        Parameters:
        scalar - galois element to multiply matrix with
        matrix - 2-dim n x n matrix to be multiplied
        Returns:
        matrix multiplied with scalar
      • addSquareMatrix

        public short[][] addSquareMatrix​(short[][] matrix1,
                                         short[][] matrix2)
        Adds the n x n matrices matrix1 and matrix2
        Parameters:
        matrix1 - first summand
        matrix2 - second summand
        Returns:
        addition of matrix1 and matrix2; both having the dimensions n x n
        Throws:
        java.lang.RuntimeException - in case the addition is not possible because of different dimensions of the matrices