FieldElementF2m extends FieldElement implements Serializable { @Override public FieldElement multInv() { if (this.getData().equals(BigInteger.ZERO)) { throw new ArithmeticException(); } if (this.getData().equals(BigInteger.ONE)) { return this; } BigInteger r2 = this.getModulus(); BigInteger r1 = this.getData(); BigInteger t2 = new BigInteger("0"); BigInteger t1 = BigInteger.ONE; do { BigInteger[] division = this.polynomialDivision(r2, r1); BigInteger r = division[1]; BigInteger q = division[0]; FieldElementF2m t1Polynomial = new FieldElementF2m(t1, this.getModulus()); FieldElementF2m qPolynomial = new FieldElementF2m(q, this.getModulus()); BigInteger t = t1Polynomial.mult(qPolynomial).getData(); t = this.reduce(t); t = t2.xor(t); t2 = t1; t1 = t; r2 = r1; r1 = r; } while (!r1.equals(BigInteger.ONE) && !r1.equals(BigInteger.ZERO)); return new FieldElementF2m(t1, this.getModulus()); } FieldElementF2m(BigInteger data, BigInteger modulus); private  FieldElementF2m(); @Override FieldElement add(FieldElement f); @Override FieldElement mult(FieldElement f); @Override FieldElement addInv(); @Override FieldElement multInv();  }
@Test public void testMultInv() { FieldElementF2m tmp = (FieldElementF2m) neutral.multInv(); assertEquals(neutral, tmp); tmp = (FieldElementF2m) p1.multInv(); FieldElementF2m result = new FieldElementF2m(new BigInteger("10", 2), modulus); assertEquals(result, tmp); tmp = (FieldElementF2m) p5.multInv(); result = new FieldElementF2m(new BigInteger("110", 2), modulus); assertEquals(result, tmp); try { zero.multInv(); fail(); } catch (ArithmeticException e) { } }