/** * Add the given polynomial to this polynomial (overwrite this). * * @param addend the addend */ public void addToThis(PolynomialGF2mSmallM addend) { coefficients = add(coefficients, addend.coefficients); computeDegree(); }
PolynomialGF2mSmallM b2 = ab[1].multiply(ab[1]); PolynomialGF2mSmallM xb2 = b2.multWithMonomial(1); PolynomialGF2mSmallM a2plusXb2 = a2.add(xb2);
/** * Compute the sum of this polynomial and the given polynomial. * * @param addend the addend * @return <tt>this + a</tt> (newly created) */ public PolynomialGF2mSmallM add(PolynomialGF2mSmallM addend) { int[] resultCoeff = add(coefficients, addend.coefficients); return new PolynomialGF2mSmallM(field, resultCoeff); }
PolynomialGF2mSmallM b2 = ab[1].multiply(ab[1]); PolynomialGF2mSmallM xb2 = b2.multWithMonomial(1); PolynomialGF2mSmallM a2plusXb2 = a2.add(xb2);
/** * Add the given polynomial to this polynomial (overwrite this). * * @param addend the addend */ public void addToThis(PolynomialGF2mSmallM addend) { coefficients = add(coefficients, addend.coefficients); computeDegree(); }
/** * Compute the sum of this polynomial and the given polynomial. * * @param addend the addend * @return <tt>this + a</tt> (newly created) */ public PolynomialGF2mSmallM add(PolynomialGF2mSmallM addend) { int[] resultCoeff = add(coefficients, addend.coefficients); return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * Compute the sum of this polynomial and the monomial of the given degree. * * @param degree the degree of the monomial * @return <tt>this + X^k</tt> */ public PolynomialGF2mSmallM addMonomial(int degree) { int[] monomial = new int[degree + 1]; monomial[degree] = 1; int[] resultCoeff = add(coefficients, monomial); return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * Compute the sum of this polynomial and the monomial of the given degree. * * @param degree the degree of the monomial * @return <tt>this + X^k</tt> */ public PolynomialGF2mSmallM addMonomial(int degree) { int[] monomial = new int[degree + 1]; monomial[degree] = 1; int[] resultCoeff = add(coefficients, monomial); return new PolynomialGF2mSmallM(field, resultCoeff); }
res2 = multiply(res2, mult2); res2 = multWithMonomial(res2, d2); result = add(res1, res2); System.arraycopy(mult2, d2, secondPartMult2, 0, secondPartMult2.length); int[] helpPoly1 = add(firstPartMult1, secondPartMult1); int[] helpPoly2 = add(firstPartMult2, secondPartMult2); int[] res1 = multiply(firstPartMult1, firstPartMult2); int[] res2 = multiply(helpPoly1, helpPoly2); int[] res3 = multiply(secondPartMult1, secondPartMult2); res2 = add(res2, res1); res2 = add(res2, res3); res3 = multWithMonomial(res3, d2); result = add(res2, res3); result = multWithMonomial(result, d2); result = add(result, res1);
res2 = multiply(res2, mult2); res2 = multWithMonomial(res2, d2); result = add(res1, res2); System.arraycopy(mult2, d2, secondPartMult2, 0, secondPartMult2.length); int[] helpPoly1 = add(firstPartMult1, secondPartMult1); int[] helpPoly2 = add(firstPartMult2, secondPartMult2); int[] res1 = multiply(firstPartMult1, firstPartMult2); int[] res2 = multiply(helpPoly1, helpPoly2); int[] res3 = multiply(secondPartMult1, secondPartMult2); res2 = add(res2, res1); res2 = add(res2, res3); res3 = multWithMonomial(res3, d2); result = add(res2, res3); result = multWithMonomial(result, d2); result = add(result, res1);
/** * 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[] g = gcd(add(u, Y), a); if (computeDegree(g) != 0)
int[] g = gcd(add(u, Y), a); if (computeDegree(g) != 0)
/** * Compute a polynomial pair (a,b) from this polynomial and the given * polynomial g with the property b*this = a mod g and deg(a)<=deg(g)/2. * * @param g the reduction polynomial * @return PolynomialGF2mSmallM[] {a,b} with b*this = a mod g and deg(a)<= * deg(g)/2 */ public PolynomialGF2mSmallM[] modPolynomialToFracton(PolynomialGF2mSmallM g) { int dg = g.degree >> 1; int[] a0 = normalForm(g.coefficients); int[] a1 = mod(coefficients, g.coefficients); int[] b0 = {0}; int[] b1 = {1}; while (computeDegree(a1) > dg) { int[][] q = div(a0, a1); a0 = a1; a1 = q[1]; int[] b2 = add(b0, modMultiply(q[0], b1, g.coefficients)); b0 = b1; b1 = b2; } return new PolynomialGF2mSmallM[]{ new PolynomialGF2mSmallM(field, a1), new PolynomialGF2mSmallM(field, b1)}; }
/** * Compute a polynomial pair (a,b) from this polynomial and the given * polynomial g with the property b*this = a mod g and deg(a)<=deg(g)/2. * * @param g the reduction polynomial * @return PolynomialGF2mSmallM[] {a,b} with b*this = a mod g and deg(a)<= * deg(g)/2 */ public PolynomialGF2mSmallM[] modPolynomialToFracton(PolynomialGF2mSmallM g) { int dg = g.degree >> 1; int[] a0 = normalForm(g.coefficients); int[] a1 = mod(coefficients, g.coefficients); int[] b0 = {0}; int[] b1 = {1}; while (computeDegree(a1) > dg) { int[][] q = div(a0, a1); a0 = a1; a1 = q[1]; int[] b2 = add(b0, modMultiply(q[0], b1, g.coefficients)); b0 = b1; b1 = b2; } return new PolynomialGF2mSmallM[]{ new PolynomialGF2mSmallM(field, a1), new PolynomialGF2mSmallM(field, b1)}; }
/** * 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; }