rscoeff := proc(f, x, p, a)
    local g, i, j, ng, cg, fs, field, ftable;
    fs := 2^(degree(p));
    field := linalg[vector](fs);
    for i from 1 to fs-1 do
        field[i] := Powmod(a, i, p, a) mod 2:
    od:
    field[fs] := 0;
    ftable := table();
    for i from 1 to fs-1 do
        ftable[ field[i] ] := a^i:
    od:
    ftable[ field[fs] ] := 0;
    g := expand(f) mod 2;
    ng := 0;
    for j from 0 to degree(g,x) do
        cg := coeff(g, x, j):
        cg := ftable[ Rem(numer(cg), p, a) mod 2 ]
              / ftable[ Rem(denom(cg), p, a) mod 2 ];
        if degree(cg,a) < 0 then
           cg := cg * a^(fs-1);
        fi:
        if degree(cg,a) = (fs-1) then
           cg := cg/a^(fs-1);
        fi:
        ng := ng + cg*x^j:
    od:
    g := sort(ng mod 2, x);
    RETURN(g);
end: