/** * Multiply this polynomial with an element from GF(2^m). * * @param element an element of the finite field GF(2^m) * @throws ArithmeticException if <tt>element</tt> is not an element of the finite * field this polynomial is defined over. */ public void multThisWithElement(int element) { if (!field.isElementOfThisField(element)) { throw new ArithmeticException( "Not an element of the finite field this polynomial is defined over."); } coefficients = multWithElement(coefficients, element); computeDegree(); }
/** * Compute the product of this polynomial with an element from GF(2^m). * * @param element an element of the finite field GF(2^m) * @return <tt>this * element</tt> (newly created) * @throws ArithmeticException if <tt>element</tt> is not an element of the finite * field this polynomial is defined over. */ public PolynomialGF2mSmallM multWithElement(int element) { if (!field.isElementOfThisField(element)) { throw new ArithmeticException( "Not an element of the finite field this polynomial is defined over."); } int[] resultCoeff = multWithElement(coefficients, element); return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * Multiply this polynomial with an element from GF(2^m). * * @param element an element of the finite field GF(2^m) * @throws ArithmeticException if <tt>element</tt> is not an element of the finite * field this polynomial is defined over. */ public void multThisWithElement(int element) { if (!field.isElementOfThisField(element)) { throw new ArithmeticException( "Not an element of the finite field this polynomial is defined over."); } coefficients = multWithElement(coefficients, element); computeDegree(); }
/** * Compute the product of this polynomial with an element from GF(2^m). * * @param element an element of the finite field GF(2^m) * @return <tt>this * element</tt> (newly created) * @throws ArithmeticException if <tt>element</tt> is not an element of the finite * field this polynomial is defined over. */ public PolynomialGF2mSmallM multWithElement(int element) { if (!field.isElementOfThisField(element)) { throw new ArithmeticException( "Not an element of the finite field this polynomial is defined over."); } int[] resultCoeff = multWithElement(coefficients, element); return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * 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); }
/** * 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); }
/** * 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; }
int[] coeff = new int[1]; coeff[0] = field.mult(headCoefficient(result[1]), hc); q = multWithElement(f, coeff[0]); int n = computeDegree(result[1]) - df; q = multWithMonomial(q, n);
int[] coeff = new int[1]; coeff[0] = field.mult(headCoefficient(result[1]), hc); q = multWithElement(f, coeff[0]); int n = computeDegree(result[1]) - df; q = multWithMonomial(q, n);
return multWithElement(mult1, mult2[0]);
return multWithElement(mult1, mult2[0]);
.multWithElement(coef); PolynomialGF2mSmallM tmpInvColumn = sqRootMatrix[i] .multWithElement(coef); tmpMatrix[j].addToThis(tmpSqColumn); sqRootMatrix[j].addToThis(tmpInvColumn);
.multWithElement(coef); PolynomialGF2mSmallM tmpInvColumn = sqRootMatrix[i] .multWithElement(coef); tmpMatrix[j].addToThis(tmpSqColumn); sqRootMatrix[j].addToThis(tmpInvColumn);
/** * Compute the result of the division of two polynomials modulo a third * polynomial over the field <tt>GF(2^m)</tt>. * * @param a the first polynomial * @param b the second polynomial * @param g the reduction polynomial * @return <tt>a * b^(-1) mod g</tt> */ private int[] modDiv(int[] a, int[] b, int[] g) { int[] r0 = normalForm(g); int[] r1 = mod(b, g); int[] s0 = {0}; int[] s1 = mod(a, g); int[] s2; int[][] q; while (computeDegree(r1) != -1) { q = div(r0, r1); r0 = normalForm(r1); r1 = normalForm(q[1]); s2 = add(s0, modMultiply(q[0], s1, g)); s0 = normalForm(s1); s1 = normalForm(s2); } int hc = headCoefficient(r0); s0 = multWithElement(s0, field.inverse(hc)); return s0; }
/** * Compute the result of the division of two polynomials modulo a third * polynomial over the field <tt>GF(2^m)</tt>. * * @param a the first polynomial * @param b the second polynomial * @param g the reduction polynomial * @return <tt>a * b^(-1) mod g</tt> */ private int[] modDiv(int[] a, int[] b, int[] g) { int[] r0 = normalForm(g); int[] r1 = mod(b, g); int[] s0 = {0}; int[] s1 = mod(a, g); int[] s2; int[][] q; while (computeDegree(r1) != -1) { q = div(r0, r1); r0 = normalForm(r1); r1 = normalForm(q[1]); s2 = add(s0, modMultiply(q[0], s1, g)); s0 = normalForm(s1); s1 = normalForm(s2); } int hc = headCoefficient(r0); s0 = multWithElement(s0, field.inverse(hc)); return s0; }
PolynomialGF2mSmallM elp = a2plusXb2.multWithElement(invHeadCoeff);
PolynomialGF2mSmallM elp = a2plusXb2.multWithElement(invHeadCoeff);