/** * Computes the greatest common divisor of <i>this</i> and <i>g</i> and * returns the result in a new PolynomialGF2n. * * @param g - * a GF2nPolynomial * @return gcd(<i>this</i>, <i>g</i>) */ public final GF2nPolynomial gcd(GF2nPolynomial g) { GF2nPolynomial a = new GF2nPolynomial(this); GF2nPolynomial b = new GF2nPolynomial(g); a.shrink(); b.shrink(); GF2nPolynomial c; GF2nPolynomial result; GF2nElement alpha; while (!b.isZero()) { c = a.remainder(b); a = b; b = c; } alpha = a.coeff[a.getDegree()]; result = a.scalarMultiply((GF2nElement)alpha.invert()); return result; }
public final GF2nPolynomial shiftLeft(int amount) { if (amount <= 0) { return new GF2nPolynomial(this); } GF2nPolynomial result = new GF2nPolynomial(size + amount, coeff[0]); result.assignZeroToElements(); for (int i = 0; i < size; i++) { result.coeff[i + amount] = coeff[i]; } return result; }
/** * Divides <i>this</i> by <i>b</i> and stores the quotient in a new * PolynomialGF2n. * * @param b the divisor * @return the quotient <i>this</i> / <i>b</i> */ public final GF2nPolynomial quotient(GF2nPolynomial b) throws RuntimeException, ArithmeticException { GF2nPolynomial[] result = new GF2nPolynomial[2]; result = divide(b); return result[0]; }
/** * Multiplies <i>this</i> by <i>b</i>, reduces the result by <i>g</i> and * returns it in a new PolynomialGF2n. * * @param b the PolynomialGF2n to multiply * @param g the modul * @return <i>this</i> * <i>b</i> mod <i>g</i> */ public final GF2nPolynomial multiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g) { return multiply(b).reduce(g); }
int hDegree; GF2nPolynomial g = new GF2nPolynomial(polynomial, this); int gDegree = g.getDegree(); int i; ut = new GF2nPolynomial(2, GF2nONBElement.ZERO(this)); ut.set(1, u); c = new GF2nPolynomial(ut); c = c.multiplyAndReduce(c, g); c = c.add(ut); h = c.gcd(g); hDegree = h.getDegree(); gDegree = g.getDegree(); g = g.quotient(h); g = new GF2nPolynomial(h); gDegree = g.getDegree(); return g.at(0);
GF2nPolynomial a = new GF2nPolynomial(this); a.shrink(); GF2nPolynomial shift; GF2nElement factor; int bDegree = b.getDegree(); GF2nElement inv = (GF2nElement)b.coeff[bDegree].invert(); if (a.getDegree() < bDegree) result[0] = new GF2nPolynomial(this); result[0].assignZeroToElements(); result[0].shrink(); result[1] = new GF2nPolynomial(this); result[1].shrink(); return result; result[0] = new GF2nPolynomial(this); result[0].assignZeroToElements(); int i = a.getDegree() - bDegree; while (i >= 0) factor = (GF2nElement)a.coeff[a.getDegree()].multiply(inv); shift = b.scalarMultiply(factor); shift.shiftThisLeft(i); a = a.add(shift); a.shrink(); result[0].coeff[i] = (GF2nElement)factor.clone(); i = a.getDegree() - bDegree; result[0].shrink();
/** * Multiplies the scalar <i>s</i> to each coefficient of this * PolynomialGF2n and returns the result in a new PolynomialGF2n. * * @param s the scalar to multiply * @return <i>this</i> x <i>s</i> */ public final GF2nPolynomial scalarMultiply(GF2nElement s) { GF2nPolynomial result = new GF2nPolynomial(size()); int i; for (i = 0; i < size(); i++) { result.coeff[i] = (GF2nElement)coeff[i].multiply(s); // result[i] // = // a[i]*s } return result; }
/** * @return the hash code of this polynomial */ public int hashCode() { return getDegree() + coeff.hashCode(); }
int oldSize = size; GF2nField f = coeff[0].getField(); enlarge(size + amount); for (i = oldSize - 1; i >= 0; i--)
int hDegree; GF2nPolynomial g = new GF2nPolynomial(polynomial, this); int gDegree = g.getDegree(); int i; ut = new GF2nPolynomial(2, GF2nPolynomialElement.ZERO(this)); ut.set(1, u); c = new GF2nPolynomial(ut); c = c.multiplyAndReduce(c, g); c = c.add(ut); h = c.gcd(g); hDegree = h.getDegree(); gDegree = g.getDegree(); g = g.quotient(h); g = new GF2nPolynomial(h); gDegree = g.getDegree(); return g.at(0);
GF2nPolynomial a = new GF2nPolynomial(this); a.shrink(); GF2nPolynomial shift; GF2nElement factor; int bDegree = b.getDegree(); GF2nElement inv = (GF2nElement)b.coeff[bDegree].invert(); if (a.getDegree() < bDegree) result[0] = new GF2nPolynomial(this); result[0].assignZeroToElements(); result[0].shrink(); result[1] = new GF2nPolynomial(this); result[1].shrink(); return result; result[0] = new GF2nPolynomial(this); result[0].assignZeroToElements(); int i = a.getDegree() - bDegree; while (i >= 0) factor = (GF2nElement)a.coeff[a.getDegree()].multiply(inv); shift = b.scalarMultiply(factor); shift.shiftThisLeft(i); a = a.add(shift); a.shrink(); result[0].coeff[i] = (GF2nElement)factor.clone(); i = a.getDegree() - bDegree; result[0].shrink();
/** * Multiplies the scalar <i>s</i> to each coefficient of this * PolynomialGF2n and returns the result in a new PolynomialGF2n. * * @param s the scalar to multiply * @return <i>this</i> x <i>s</i> * @throws DifferentFieldsException if <tt>this</tt> and <tt>s</tt> are not defined over * the same field. */ public final GF2nPolynomial scalarMultiply(GF2nElement s) throws RuntimeException { GF2nPolynomial result = new GF2nPolynomial(size()); int i; for (i = 0; i < size(); i++) { result.coeff[i] = (GF2nElement)coeff[i].multiply(s); // result[i] // = // a[i]*s } return result; }
/** * Multiplies <i>this</i> by <i>b</i>, reduces the result by <i>g</i> and * returns it in a new PolynomialGF2n. * * @param b the PolynomialGF2n to multiply * @param g the modul * @return <i>this</i> * <i>b</i> mod <i>g</i> * @throws DifferentFieldsException if <tt>this</tt>, <tt>b</tt> and <tt>g</tt> are * not all defined over the same field. */ public final GF2nPolynomial multiplyAndReduce(GF2nPolynomial b, GF2nPolynomial g) throws RuntimeException, ArithmeticException { return multiply(b).reduce(g); }
/** * @return the hash code of this polynomial */ public int hashCode() { return getDegree() + coeff.hashCode(); }
int oldSize = size; GF2nField f = coeff[0].getField(); enlarge(size + amount); for (i = oldSize - 1; i >= 0; i--)
int hDegree; GF2nPolynomial g = new GF2nPolynomial(polynomial, this); int gDegree = g.getDegree(); int i; ut = new GF2nPolynomial(2, GF2nONBElement.ZERO(this)); ut.set(1, u); c = new GF2nPolynomial(ut); c = c.multiplyAndReduce(c, g); c = c.add(ut); h = c.gcd(g); hDegree = h.getDegree(); gDegree = g.getDegree(); g = g.quotient(h); g = new GF2nPolynomial(h); gDegree = g.getDegree(); return g.at(0);
throws RuntimeException, ArithmeticException GF2nPolynomial a = new GF2nPolynomial(this); GF2nPolynomial b = new GF2nPolynomial(g); a.shrink(); b.shrink(); GF2nPolynomial c; GF2nPolynomial result; GF2nElement alpha; while (!b.isZero()) c = a.remainder(b); a = b; b = c; alpha = a.coeff[a.getDegree()]; result = a.scalarMultiply((GF2nElement)alpha.invert()); return result;
if (size() >= b.size()) result = new GF2nPolynomial(size()); int i; for (i = 0; i < b.size(); i++) for (; i < size(); i++) result = new GF2nPolynomial(b.size()); int i; for (i = 0; i < size(); i++) for (; i < b.size(); i++)
public final GF2nPolynomial shiftLeft(int amount) { if (amount <= 0) { return new GF2nPolynomial(this); } GF2nPolynomial result = new GF2nPolynomial(size + amount, coeff[0]); result.assignZeroToElements(); for (int i = 0; i < size; i++) { result.coeff[i + amount] = coeff[i]; } return result; }
public final boolean equals(Object other) { if (other == null || !(other instanceof GF2nPolynomial)) { return false; } GF2nPolynomial otherPol = (GF2nPolynomial)other; if (getDegree() != otherPol.getDegree()) { return false; } int i; for (i = 0; i < size; i++) { if (!coeff[i].equals(otherPol.coeff[i])) { return false; } } return true; }