private void multRowWithElementThis(int[] row, int element) { for (int i = row.length - 1; i >= 0; i--) { row[i] = field.mult(row[i], element); } }
private int[] multRowWithElement(int[] row, int element) { int[] result = new int[row.length]; for (int i = row.length - 1; i >= 0; i--) { result[i] = field.mult(row[i], element); } return result; }
private int[] multRowWithElement(int[] row, int element) { int[] result = new int[row.length]; for (int i = row.length - 1; i >= 0; i--) { result[i] = field.mult(row[i], element); } return result; }
private void multRowWithElementThis(int[] row, int element) { for (int i = row.length - 1; i >= 0; i--) { row[i] = field.mult(row[i], element); } }
private void multRowWithElementThis(int[] row, int element) { for (int i = row.length - 1; i >= 0; i--) { row[i] = field.mult(row[i], element); } }
private int[] multRowWithElement(int[] row, int element) { int[] result = new int[row.length]; for (int i = row.length - 1; i >= 0; i--) { result[i] = field.mult(row[i], element); } return result; }
/** * compute the square root of an integer * * @param a a field element a * @return a<sup>1/2</sup> */ public int sqRoot(int a) { for (int i = 1; i < degree; i++) { a = mult(a, a); } return a; }
/** * compute the square root of an integer * * @param a a field element a * @return a<sup>1/2</sup> */ public int sqRoot(int a) { for (int i = 1; i < degree; i++) { a = mult(a, a); } return a; }
/** * Evaluate this polynomial <tt>p</tt> at a value <tt>e</tt> (in * <tt>GF(2^m)</tt>) with the Horner scheme. * * @param e the element of the finite field GF(2^m) * @return <tt>this(e)</tt> */ public int evaluateAt(int e) { int result = coefficients[degree]; for (int i = degree - 1; i >= 0; i--) { result = field.mult(result, e) ^ coefficients[i]; } return result; }
/** * Evaluate this polynomial <tt>p</tt> at a value <tt>e</tt> (in * <tt>GF(2^m)</tt>) with the Horner scheme. * * @param e the element of the finite field GF(2^m) * @return <tt>this(e)</tt> */ public int evaluateAt(int e) { int result = coefficients[degree]; for (int i = degree - 1; i >= 0; i--) { result = field.mult(result, e) ^ coefficients[i]; } return result; }
/** * Compute the product of a polynomial a with an element from the finite * field <tt>GF(2^m)</tt>. * * @param a the polynomial * @param element an element of the finite field GF(2^m) * @return <tt>a * element</tt> */ private int[] multWithElement(int[] a, int element) { int degree = computeDegree(a); if (degree == -1 || element == 0) { return new int[1]; } if (element == 1) { return IntUtils.clone(a); } int[] result = new int[degree + 1]; for (int i = degree; i >= 0; i--) { result[i] = field.mult(a[i], element); } return result; }
/** * Compute the product of a polynomial a with an element from the finite * field <tt>GF(2^m)</tt>. * * @param a the polynomial * @param element an element of the finite field GF(2^m) * @return <tt>a * element</tt> */ private int[] multWithElement(int[] a, int element) { int degree = computeDegree(a); if (degree == -1 || element == 0) { return new int[1]; } if (element == 1) { return IntUtils.clone(a); } int[] result = new int[degree + 1]; for (int i = degree; i >= 0; i--) { result[i] = field.mult(a[i], element); } return result; }
int scalarTerm = field.mult(matrix[j].coefficients[i], coefficients[j]); resultCoeff[i] = field.add(resultCoeff[i], scalarTerm);
int scalarTerm = field.mult(matrix[j].coefficients[i], coefficients[j]); resultCoeff[i] = field.add(resultCoeff[i], scalarTerm);
public GF2mMatrixEx rightMultiply(GF2mMatrixEx a) { if (this.getNumColumns() != a.getNumRows()){ throw new IllegalArgumentException("Dimension mismatch"); } final int[][] ai = a.getMatrix(); final int columnsInA = a.getNumColumns(); GF2mMatrixEx res = new GF2mMatrixEx(this.field, this.numRows, columnsInA); final int[][] ri = res.getMatrix(); for (int i = 0; i < this.numRows; i++) { for (int j = 0; j < columnsInA; j++) { for (int k = 0; k < this.numColumns; k++) { ri[i][j] = field.add(ri[i][j], field.mult(matrix[i][k], ai[k][j])); } } } return res; }
/** * Reduce a polynomial modulo another polynomial. * * @param a the polynomial * @param f the reduction polynomial * @return <tt>a mod f</tt> */ private int[] mod(int[] a, int[] f) { int df = computeDegree(f); if (df == -1) { throw new ArithmeticException("Division by zero"); } int[] result = new int[a.length]; int hc = headCoefficient(f); hc = field.inverse(hc); System.arraycopy(a, 0, result, 0, result.length); while (df <= computeDegree(result)) { int[] q; int coeff = field.mult(headCoefficient(result), hc); q = multWithMonomial(f, computeDegree(result) - df); q = multWithElement(q, coeff); result = add(q, result); } return result; }
/** * Reduce a polynomial modulo another polynomial. * * @param a the polynomial * @param f the reduction polynomial * @return <tt>a mod f</tt> */ private int[] mod(int[] a, int[] f) { int df = computeDegree(f); if (df == -1) { throw new ArithmeticException("Division by zero"); } int[] result = new int[a.length]; int hc = headCoefficient(f); hc = field.inverse(hc); System.arraycopy(a, 0, result, 0, result.length); while (df <= computeDegree(result)) { int[] q; int coeff = field.mult(headCoefficient(result), hc); q = multWithMonomial(f, computeDegree(result) - df); q = multWithElement(q, coeff); result = add(q, result); } return result; }