if (isZero()) GF2Polynomial f = new GF2Polynomial(this); int d, i; GF2Polynomial u, g; GF2Polynomial dummy; f.reduceN(); d = f.len - 1; u = new GF2Polynomial(f.len, "X"); u.squareThisPreCalc(); u = u.remainder(f); dummy = u.add(new GF2Polynomial(32, "X")); if (!dummy.isZero()) g = f.gcd(dummy); if (!g.isOne())
fieldPolynomial = new GF2Polynomial(mDegree + 1, "ALL"); GF2Polynomial q = new GF2Polynomial(mDegree + 1, "ONE"); GF2Polynomial p = new GF2Polynomial(mDegree + 1, "X"); p.addToThis(q); GF2Polynomial r; int i; p = q.shiftLeft(); p.addToThis(r);
/** * Assigns the value 'one' to this Polynomial. */ void assignOne() { polynomial.assignOne(); }
/** * Toggles the LSB of this GF2Polynomial, increasing the value by 'one' and * returns the result in a new GF2Polynomial. * * @return <tt>this + 1</tt> */ public GF2Polynomial increase() { GF2Polynomial result = new GF2Polynomial(this); result.increaseThis(); return result; }
GF2Polynomial result = new GF2Polynomial(len << 1); if (len <= 32) result.value = mult32(value[0], b.value[0]); return result; result.value = mult64(value, b.value); return result; result.value = mult128(value, b.value); return result; result.value = mult256(value, b.value); return result; result.value = mult512(value, b.value); return result; GF2Polynomial a0 = lower(((n - 1) >> 5) + 1); GF2Polynomial a1 = upper(((n - 1) >> 5) + 1); GF2Polynomial b0 = b.lower(((n - 1) >> 5) + 1); GF2Polynomial b1 = b.upper(((n - 1) >> 5) + 1); GF2Polynomial c = a1.karaMult(b1); // c = a1*b1 GF2Polynomial e = a0.karaMult(b0); // e = a0*b0 a0.addToThis(a1); // a0 = a0 + a1 b0.addToThis(b1); // b0 = b0 + b1 GF2Polynomial d = a0.karaMult(b0); // d = (a0+a1)*(b0+b1)
GF2Polynomial q = new GF2Polynomial(len); GF2Polynomial a = new GF2Polynomial(this); GF2Polynomial b = new GF2Polynomial(g); GF2Polynomial j; int i; if (b.isZero()) a.reduceN(); b.reduceN(); if (a.len < b.len) return new GF2Polynomial(0); q.expandN(i + 1); j = b.shiftLeft(i); a.subtractFromThis(j); a.reduceN(); q.xorBit(i); i = a.len - b.len;
/** * Reduce this GF2nPolynomialElement using the trinomial x^n + x^tc + 1 as * fieldpolynomial. The coefficients are reduced bit by bit. */ private void reduceTrinomialBitwise(int tc) { int i; int k = mDegree - tc; for (i = polynomial.getLength() - 1; i >= mDegree; i--) { if (polynomial.testBit(i)) { polynomial.xorBit(i); polynomial.xorBit(i - k); polynomial.xorBit(i - mDegree); } } polynomial.reduceN(); polynomial.expandN(mDegree); }
GF2Polynomial b = new GF2Polynomial(mDegree, "ONE"); GF2Polynomial c = new GF2Polynomial(mDegree); GF2Polynomial u = getGF2Polynomial(); GF2Polynomial v = mField.getFieldPolynomial(); while (true) while (!u.testBit(0)) u.shiftRightThis(); // u = u / x if (!b.testBit(0)) b.shiftRightThis(); b.addToThis(mField.getFieldPolynomial()); b.shiftRightThis(); if (u.isOne()) u.reduceN(); v.reduceN(); if (u.getLength() < v.getLength()) c = h; u.addToThis(v); b.addToThis(c);
if (fieldPolynomial.equals(basis.fieldPolynomial)) GF2Polynomial bs = new GF2Polynomial(mDegree, elemCopy.toFlexiBigInt()); bs.expandN(mDegree); GF2Polynomial result = new GF2Polynomial(mDegree); for (i = 0; i < mDegree; i++) if (bs.vectorMult(COBMatrix[i])) result.setBit(mDegree - 1 - i); result.toFlexiBigInt());
GF2Polynomial a = new GF2Polynomial(this); GF2Polynomial b = new GF2Polynomial(g); GF2Polynomial j; int i; if (b.isZero()) a.reduceN(); b.reduceN(); if (a.len < b.len) while (i >= 0) j = b.shiftLeft(i); a.subtractFromThis(j); a.reduceN(); i = a.len - b.len;
for (i = 0; i < squaringMatrix.length; i++) squaringMatrix[i] = new GF2Polynomial(mDegree, "ZERO"); d[i] = new GF2Polynomial(1, "ONE").shiftLeft(mDegree + i) .remainder(fieldPolynomial); if (d[mDegree - (i << 1)].testBit(mDegree - j)) squaringMatrix[j - 1].setBit(mDegree - i); squaringMatrix[(i << 1) - mDegree - 1].setBit(mDegree - i);
if (value.equalsIgnoreCase("ZERO")) assignZero(); assignOne(); randomize(); assignX(); assignAll();
if (polynomial.getLength() > mDegree) || (polynomial.getLength() > (mDegree << 1))) polynomial.reduceTrinomial(mDegree, tc); return; || (polynomial.getLength() > (mDegree << 1))) polynomial.reducePentanomial(mDegree, pc); return; polynomial = polynomial.remainder(mField.getFieldPolynomial()); polynomial.expandN(mDegree); return; if (polynomial.getLength() < mDegree) polynomial.expandN(mDegree);
/** * Tests random polynomials of degree (n+1) until an irreducible is found * and stores the result in <i>field polynomial</i>. This can take very * long for huge degrees. * * @return true */ private boolean testRandom() { int l; boolean done = false; fieldPolynomial = new GF2Polynomial(mDegree + 1); l = 0; while (!done) { l++; fieldPolynomial.randomize(); fieldPolynomial.setBit(mDegree); fieldPolynomial.setBit(0); if (fieldPolynomial.isIrreducible()) { done = true; return done; } } return done; }
l = 0; fieldPolynomial = new GF2Polynomial(mDegree + 1); fieldPolynomial.setBit(0); fieldPolynomial.setBit(mDegree); for (i = 1; (i < mDegree) && !done; i++) fieldPolynomial.setBit(i); done = fieldPolynomial.isIrreducible(); l++; if (done) return done; fieldPolynomial.resetBit(i); done = fieldPolynomial.isIrreducible();
GF2Polynomial result = new GF2Polynomial(Math.max(len, b.len) << 1); GF2Polynomial[] m = new GF2Polynomial[32]; int i, j; m[0] = new GF2Polynomial(this); for (i = 1; i <= 31; i++) m[i] = m[i - 1].shiftLeft(); result.xorThisBy(m[j]); m[j].shiftBlocksLeft();
a[i] = new GF2Polynomial(matrix[i]); inv[i] = new GF2Polynomial(mDegree); inv[i].setBit(mDegree - 1 - i); while ((j < mDegree) && !a[j].testBit(mDegree - 1 - i)) if (a[j].testBit(mDegree - 1 - i)) a[j].addToThis(a[i]); inv[j].addToThis(inv[i]); if (a[j].testBit(mDegree - 1 - i)) a[j].addToThis(a[i]); inv[j].addToThis(inv[i]);
/** * @return a copy of this GF2Polynomial */ public Object clone() { return new GF2Polynomial(this); }