def eucldiv(self, a, b):
    ' Return a/b and a%b\n            a and b are of length d-1 where d is the degree of the irreducible polynomial\n        '
    zero = self.F.zero()
    izero = self.zero()
    d = self.deg
    assert (not b.poly.iszero())
    if a.poly.iszero():
        return (izero, izero)
    elif (a == b):
        return (self.one(), izero)
    A = a.poly.coef
    B = b.poly.coef
    (n, da) = a.poly.truedeg()
    (m, db) = b.poly.truedeg()
    if (da < db):
        return (izero, a)
    elif (da == db):
        deg = max((d - 1), da)
        rc = ([zero] * deg)
        qc = ([zero] * deg)
        q = (A[n] / B[m])
        for i in range(1, deg):
            rc[i] = (A[(n + i)] - (q * B[(m + i)]))
        qc[(deg - 1)] = q
        rp = polynom(self.F, rc)
        qp = polynom(self.F, qc)
        remain = ExtensionFieldElem(self, rp)
        quotient = ExtensionFieldElem(self, qp)
        return (quotient, remain)
    else:
        deg = max((d - 1), da)
        p = (deg - da)
        rc = ([zero] * deg)
        qc = ([zero] * deg)
        rc[(deg - da):] = A[n:]
        pm = 0
        while (((p + pm) + db) < (deg + 1)):
            k = (((deg - (da - db)) - 1) + pm)
            qc[k] = (rc[(p + pm)] / B[m])
            for i in range(db):
                rc[((i + p) + pm)] = (rc[((i + p) + pm)] - (qc[k] * B[(m + i)]))
            pm = (pm + 1)
        rp = polynom(self.F, rc)
        qp = polynom(self.F, qc)
        remain = ExtensionFieldElem(self, rp)
        quotient = ExtensionFieldElem(self, qp)
        return (quotient, remain)
Return a/b and a%b
a and b are of length d-1 where d is the degree of the irreducible polynomial
def eucldiv(self, a, b):
    ' Return a/b and a%b\n            a and b are of length d-1 where d is the degree of the irreducible polynomial\n        '
    zero = self.F.zero()
    izero = self.zero()
    d = self.deg
    assert (not b.poly.iszero())
    if a.poly.iszero():
        return (izero, izero)
    elif (a == b):
        return (self.one(), izero)
    A = a.poly.coef
    B = b.poly.coef
    (n, da) = a.poly.truedeg()
    (m, db) = b.poly.truedeg()
    if (da < db):
        return (izero, a)
    elif (da == db):
        deg = max((d - 1), da)
        rc = ([zero] * deg)
        qc = ([zero] * deg)
        q = (A[n] / B[m])
        for i in range(1, deg):
            rc[i] = (A[(n + i)] - (q * B[(m + i)]))
        qc[(deg - 1)] = q
        rp = polynom(self.F, rc)
        qp = polynom(self.F, qc)
        remain = ExtensionFieldElem(self, rp)
        quotient = ExtensionFieldElem(self, qp)
        return (quotient, remain)
    else:
        deg = max((d - 1), da)
        p = (deg - da)
        rc = ([zero] * deg)
        qc = ([zero] * deg)
        rc[(deg - da):] = A[n:]
        pm = 0
        while (((p + pm) + db) < (deg + 1)):
            k = (((deg - (da - db)) - 1) + pm)
            qc[k] = (rc[(p + pm)] / B[m])
            for i in range(db):
                rc[((i + p) + pm)] = (rc[((i + p) + pm)] - (qc[k] * B[(m + i)]))
            pm = (pm + 1)
        rp = polynom(self.F, rc)
        qp = polynom(self.F, qc)
        remain = ExtensionFieldElem(self, rp)
        quotient = ExtensionFieldElem(self, qp)
        return (quotient, remain)