public GF2mField getField() { return new GF2mField(encField); }
/** * Add one row to another. * * @param fromRow the addend * @param toRow the row to add to */ private void addToRow(int[] fromRow, int[] toRow) { for (int i = toRow.length - 1; i >= 0; i--) { toRow[i] = field.add(fromRow[i], toRow[i]); } }
public String toString() { String str = this.numRows + " x " + this.numColumns + " Matrix over " + this.field.toString() + ": \n"; for (int i = 0; i < this.numRows; i++) { for (int j = 0; j < this.numColumns; j++) { str = str + this.field.elementToStr(matrix[i][j]) + " : "; } str = str + "\n"; } return str; }
while (field.getDegree() > d) if (!this.field.isElementOfThisField(matrix[i][j]))
this.field = new GF2mField(field); while (field.getDegree() > d) if (!field.isElementOfThisField(vector[i]))
/** * @return a byte array encoding of this vector */ public byte[] getEncoded() { int d = 8; int count = 1; while (field.getDegree() > d) { count++; d += 8; } byte[] res = new byte[vector.length * count]; count = 0; for (int i = 0; i < vector.length; i++) { for (int j = 0; j < d; j += 8) { res[count++] = (byte)(vector[i] >>> j); } } return res; }
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; }
/** * @return the hash code of this polynomial */ public int hashCode() { int hash = field.hashCode(); for (int j = 0; j < coefficients.length; j++) { hash = hash * 31 + coefficients[j]; } return hash; }
if ((!this.field.equals(otherMatrix.field)) || (otherMatrix.numRows != this.numColumns) || (otherMatrix.numColumns != this.numColumns))
/** * Create a new vector over <tt>GF(2<sup>m</sup>)</tt> of the given * length and element array. * * @param field the finite field <tt>GF(2<sup>m</sup>)</tt> * @param vector the element array */ public GF2mVector(GF2mField field, int[] vector) { this.field = field; length = vector.length; for (int i = vector.length - 1; i >= 0; i--) { if (!field.isElementOfThisField(vector[i])) { throw new ArithmeticException( "Element array is not specified over the given finite field."); } } this.vector = IntUtils.clone(vector); }
/** * Return the greatest common divisor of two polynomials over the field * <tt>GF(2^m)</tt>. * * @param f the first polynomial * @param g the second polynomial * @return <tt>gcd(f, g)</tt> */ private int[] gcd(int[] f, int[] g) { int[] a = f; int[] b = g; if (computeDegree(a) == -1) { return b; } while (computeDegree(b) != -1) { int[] c = mod(a, b); a = new int[b.length]; System.arraycopy(b, 0, a, 0, a.length); b = new int[c.length]; System.arraycopy(c, 0, b, 0, b.length); } int coeff = field.inverse(headCoefficient(a)); return multWithElement(a, coeff); }
while (field.getDegree() > d) if (!this.field.isElementOfThisField(matrix[i][j]))