/** * Compute the product of this polynomial and another polynomial modulo a * third polynomial. * * @param a another polynomial * @param b the reduction polynomial * @return <tt>this * a mod b</tt> */ public PolynomialGF2mSmallM modMultiply(PolynomialGF2mSmallM a, PolynomialGF2mSmallM b) { int[] resultCoeff = modMultiply(coefficients, a.coefficients, b.coefficients); return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * Compute the product of this polynomial and another polynomial modulo a * third polynomial. * * @param a another polynomial * @param b the reduction polynomial * @return <tt>this * a mod b</tt> */ public PolynomialGF2mSmallM modMultiply(PolynomialGF2mSmallM a, PolynomialGF2mSmallM b) { int[] resultCoeff = modMultiply(coefficients, a.coefficients, b.coefficients); return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * Compute the square root of this polynomial modulo the given polynomial. * * @param a the reduction polynomial * @return <tt>this^(1/2) mod a</tt> */ public PolynomialGF2mSmallM modSquareRoot(PolynomialGF2mSmallM a) { int[] resultCoeff = IntUtils.clone(coefficients); int[] help = modMultiply(resultCoeff, resultCoeff, a.coefficients); while (!isEqual(help, coefficients)) { resultCoeff = normalForm(help); help = modMultiply(resultCoeff, resultCoeff, a.coefficients); } return new PolynomialGF2mSmallM(field, resultCoeff); }
/** * Compute the square root of this polynomial modulo the given polynomial. * * @param a the reduction polynomial * @return <tt>this^(1/2) mod a</tt> */ public PolynomialGF2mSmallM modSquareRoot(PolynomialGF2mSmallM a) { int[] resultCoeff = IntUtils.clone(coefficients); int[] help = modMultiply(resultCoeff, resultCoeff, a.coefficients); while (!isEqual(help, coefficients)) { resultCoeff = normalForm(help); help = modMultiply(resultCoeff, resultCoeff, a.coefficients); } return new PolynomialGF2mSmallM(field, resultCoeff); }
u = modMultiply(u, u, a);
u = modMultiply(u, u, a);
/** * 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; }