/** * Return the remainder of a polynomial division of two polynomials. * * @param p dividend * @param q divisor * @return <tt>p mod q</tt> */ public static int remainder(int p, int q) { int result = p; if (q == 0) { System.err.println("Error: to be divided by 0"); return 0; } while (degree(result) >= degree(q)) { result ^= q << (degree(result) - degree(q)); } return result; }
/** * Return the remainder of a polynomial division of two polynomials. * * @param p dividend * @param q divisor * @return <tt>p mod q</tt> */ public static int remainder(int p, int q) { int result = p; if (q == 0) { System.err.println("Error: to be divided by 0"); return 0; } while (degree(result) >= degree(q)) { result ^= q << (degree(result) - degree(q)); } return result; }
/** * Return the rest of devision two polynomials * * @param p polinomial * @param q polinomial * @return p mod q */ public static int rest(long p, int q) { long p1 = p; if (q == 0) { System.err.println("Error: to be divided by 0"); return 0; } long q1 = q & 0x00000000ffffffffL; while ((p1 >>> 32) != 0) { p1 ^= q1 << (degree(p1) - degree(q1)); } int result = (int)(p1 & 0xffffffff); while (degree(result) >= degree(q)) { result ^= q << (degree(result) - degree(q)); } return result; }
/** * Return the rest of devision two polynomials * * @param p polinomial * @param q polinomial * @return p mod q */ public static int rest(long p, int q) { long p1 = p; if (q == 0) { System.err.println("Error: to be divided by 0"); return 0; } long q1 = q & 0x00000000ffffffffL; while ((p1 >>> 32) != 0) { p1 ^= q1 << (degree(p1) - degree(q1)); } int result = (int)(p1 & 0xffffffff); while (degree(result) >= degree(q)) { result ^= q << (degree(result) - degree(q)); } return result; }
/** * create a finite field GF(2^m) with the fixed field polynomial * * @param degree the degree of the field * @param poly the field polynomial */ public GF2mField(int degree, int poly) { if (degree != PolynomialRingGF2.degree(poly)) { throw new IllegalArgumentException( " Error: the degree is not correct"); } if (!PolynomialRingGF2.isIrreducible(poly)) { throw new IllegalArgumentException( " Error: given polynomial is reducible"); } this.degree = degree; polynomial = poly; }
/** * create a finite field GF(2^m) with the fixed field polynomial * * @param degree the degree of the field * @param poly the field polynomial */ public GF2mField(int degree, int poly) { if (degree != PolynomialRingGF2.degree(poly)) { throw new IllegalArgumentException( " Error: the degree is not correct"); } if (!PolynomialRingGF2.isIrreducible(poly)) { throw new IllegalArgumentException( " Error: given polynomial is reducible"); } this.degree = degree; polynomial = poly; }
public GF2mField(byte[] enc) { if (enc.length != 4) { throw new IllegalArgumentException( "byte array is not an encoded finite field"); } polynomial = LittleEndianConversions.OS2IP(enc); if (!PolynomialRingGF2.isIrreducible(polynomial)) { throw new IllegalArgumentException( "byte array is not an encoded finite field"); } degree = PolynomialRingGF2.degree(polynomial); }
public GF2mField(byte[] enc) { if (enc.length != 4) { throw new IllegalArgumentException( "byte array is not an encoded finite field"); } polynomial = LittleEndianConversions.OS2IP(enc); if (!PolynomialRingGF2.isIrreducible(polynomial)) { throw new IllegalArgumentException( "byte array is not an encoded finite field"); } degree = PolynomialRingGF2.degree(polynomial); }
if ((PolynomialRingGF2.degree(poly) == m) && (PolynomialRingGF2.isIrreducible(poly)))
if ((PolynomialRingGF2.degree(poly) == m) && (PolynomialRingGF2.isIrreducible(poly)))
if ((PolynomialRingGF2.degree(poly) == m) && (PolynomialRingGF2.isIrreducible(poly)))
if ((PolynomialRingGF2.degree(poly) == m) && (PolynomialRingGF2.isIrreducible(poly)))
/** * Checking polynomial for irreducibility * * @param p polinomial * @return true if p is irreducible and false otherwise */ public static boolean isIrreducible(int p) { if (p == 0) { return false; } int d = degree(p) >>> 1; int u = 2; for (int i = 0; i < d; i++) { u = modMultiply(u, u, p); if (gcd(u ^ 2, p) != 1) { return false; } } return true; }
/** * Checking polynomial for irreducibility * * @param p polinomial * @return true if p is irreducible and false otherwise */ public static boolean isIrreducible(int p) { if (p == 0) { return false; } int d = degree(p) >>> 1; int u = 2; for (int i = 0; i < d; i++) { u = modMultiply(u, u, p); if (gcd(u ^ 2, p) != 1) { return false; } } return true; }
if (q != 0) int d = 1 << degree(r);
if (q != 0) int d = 1 << degree(r);