Here you can find the source of multiplyMatrix(int[][] a, int[] b, int mod)
Parameter | Description |
---|---|
a | The matrix to multiply with. a.length = b.length |
b | A vector to multiply with the matrix where b.length = a.length |
mod | The modulus used. See HillCipher.ALPHA_CHARS, HillCipher.ALL_CHARS for options |
public static int[] multiplyMatrix(int[][] a, int[] b, int mod)
//package com.java2s; //License from project: Open Source License public class Main { /**// ww w . ja va 2 s. c o m * Multiplies the input matrix a with the input vector b % mod * @param a The matrix to multiply with. a.length = b.length * @param b A vector to multiply with the matrix where b.length = a.length * @param mod The modulus used. See HillCipher.ALPHA_CHARS, HillCipher.ALL_CHARS for options * @return The vector product of the multiplication (a, b) % mod */ public static int[] multiplyMatrix(int[][] a, int[] b, int mod) { int m = b.length; int[] resultMatrix = new int[m]; for (int i = 0; i < m; i++) { int total = 0; for (int j = 0; j < m; j++) { int aValue = a[i][j]; int bValue = b[j]; total += aValue * bValue; } resultMatrix[i] = total % mod; } return resultMatrix; } }