def gf_sqr(f, p, K):
 df = gf_degree(f)
 dh = (2 * df)
 h = ([0] * (dh + 1))
 for i in range(0, (dh + 1)):
  coeff = K.zero
  jmin = max(0, (i - df))
  jmax = min(i, df)
  n = ((jmax - jmin) + 1)
  jmax = ((jmin + (n // 2)) - 1)
  for j in range(jmin, (jmax + 1)):
   coeff += (f[j] * f[(i - j)])
  coeff += coeff
  if (n & 1):
   elem = f[(jmax + 1)]
   coeff += (elem ** 2)
  h[i] = (coeff % p)
 return gf_strip(h)

def gf_sqr ( f , p , K ) : df = gf_degree ( f ) dh = ( 2 * df ) h = ( [ 0 ] * ( dh + 1 ) ) for i in range ( 0 , ( dh + 1 ) ) : coeff = K . zero jmin = max ( 0 , ( i - df ) ) jmax = min ( i , df ) n = ( ( jmax - jmin ) + 1 ) jmax = ( ( jmin + ( n // 2 ) ) - 1 ) for j in range ( jmin , ( jmax + 1 ) ) : coeff += ( f [ j ] * f [ ( i - j ) ] ) coeff += coeff if ( n & 1 ) : elem = f [ ( jmax + 1 ) ] coeff += ( elem ** 2 ) h [ i ] = ( coeff % p ) return gf_strip ( h )
square polynomials in gf(p)[x] .