## Example of a Goppa code [19,7] over F5

from PyECC import *

F5 = Zn(5)

# Creating F25, with generador x such that x**2-2=0
[F25,x] = extension(F5,[1,0,-2],'x','F25')

# Creating the polynomial ring F25[T]
[A,T] = polynomial_ring(F25,'T')

# Set of non-zero elements of F25
# [1:] excludes the element of index 0, which is 0>>F25
a = Set(F25)[1:] 

# Creating a polynomial p
p = T**6 + T**3 + T + 1

# List of elements of a which are not roots of p
a = [t for t in a if evaluate(p,t)!=0]
n = len(a) 
show('n :',n)

# Creating the Goppa code C associated to p and a
C = Goppa(p,a)

# A control matrix of C is obtained from H_(C)
H = blow(H_(C),F5)
k = n - rank(H)
show('k :',k)

'''
In the example above, $p$ has six roots
($2$, $2$, $3$, $4$, $a+2$, $4a+2$) 
and hence the length of the code is
$25-1-5=19$. The rank of $H$ turns out 
to be $12$ and consequently 
$k=19-12=7$.
'''

# Example of decoding
# Generating a random error vector of weight 3
e = rd_error_vector(n,3,F5)
show('e :',e)

# Descoding of e with PGZ
x1 = PGZ(e,C)

show('x1 :',x1)

