def gf_ddf_zassenhaus(f, p, K):
 (i, g, factors) = (1, [K.one, K.zero], [])
 b = gf_frobenius_monomial_base(f, p, K)
 while ((2 * i) <= gf_degree(f)):
  g = gf_frobenius_map(g, f, b, p, K)
  h = gf_gcd(f, gf_sub(g, [K.one, K.zero], p, K), p, K)
  if (h != [K.one]):
   factors.append((h, i))
   f = gf_quo(f, h, p, K)
   g = gf_rem(g, f, p, K)
   b = gf_frobenius_monomial_base(f, p, K)
  i += 1
 if (f != [K.one]):
  return (factors + [(f, gf_degree(f))])
 else:
  return factors

def gf_ddf_zassenhaus ( f , p , K ) : ( i , g , factors ) = ( 1 , [ K . one , K . zero ] , [ ] ) b = gf_frobenius_monomial_base ( f , p , K ) while ( ( 2 * i ) <= gf_degree ( f ) ) : g = gf_frobenius_map ( g , f , b , p , K ) h = gf_gcd ( f , gf_sub ( g , [ K . one , K . zero ] , p , K ) , p , K ) if ( h != [ K . one ] ) : factors . append ( ( h , i ) ) f = gf_quo ( f , h , p , K ) g = gf_rem ( g , f , p , K ) b = gf_frobenius_monomial_base ( f , p , K ) i += 1 if ( f != [ K . one ] ) : return ( factors + [ ( f , gf_degree ( f ) ) ] ) else : return factors
cantor-zassenhaus: deterministic distinct degree factorization given a monic square-free polynomial f in gf(p)[x] .