Basic encoding and decoding

Warning: if you do not have a copy of our bitbucket repository, these examples will not work!

{{{id=1| F = GF(23) n, k = 15, 7 C = GeneralizedReedSolomonCode(F.list()[:n], k) C /// }}}

We want to encode an element of the message space

{{{id=32| V = VectorSpace(F, k) m = V.random_element() print m /// }}} {{{id=2| c = C.encode(m) print c /// }}} {{{id=33| print c in C /// }}}

Now we can decode it

{{{id=40| y = copy(c) y[5] += 1 y[7] += 1 y[11] += 1 print y in C /// }}} {{{id=34| c_dec = C.decode_to_code(y) print c_dec == c /// }}}

And we can even get back to the original message

{{{id=6| m_dec = C.decode_to_message(y) print m_dec == m /// }}}

Advanced encoding and decoding

I want to select a specific encoder

{{{id=39| C.encoders_available() /// }}} {{{id=13| Enc_vect = C.encoder('EvaluationVector') print Enc_vect /// }}} {{{id=35| Enc_poly = C.encoder('EvaluationPolynomial') print Enc_poly /// }}}

Encoders are cached

{{{id=14| C._cached_encoders /// }}}

Encoding and recovery

{{{id=18| c = Enc_vect.encode(m) print c /// }}} {{{id=41| c in C /// }}} {{{id=19| p = Enc_poly.unencode(c) print p /// }}} {{{id=20| Enc_poly.encode(p) /// }}} {{{id=21| print Enc_poly.message_space() /// }}} {{{id=36| print Enc_vect.message_space() /// }}}

Decode from a code, or decode from a decoder?

{{{id=22| C.decoders_available() /// }}} {{{id=24| Gao = C.decoder('Gao') Gao /// }}} {{{id=25| print y print y in C /// }}} {{{id=26| print Gao.connected_encoder() /// }}} {{{id=38| print Gao.message_space() /// }}} {{{id=28| Gao.decode_to_message(y) /// }}} {{{id=29| C.decode_to_message(y) /// }}} {{{id=30| C.decoder() /// }}} {{{id=42| /// }}}