-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I have attempted to encode a message using a Cauchy Reed Solomon using 4 symbols and 2 parities. It has been done using the encoding_fragments
and decoding_fragments
functions below:
import math
import pyerasure
import pyerasure.finite_field
import pyerasure.generator
def encoding_fragments(data_in: bytes, symbols: int, parity: int):
# padding input to ensure correct size
symbol_bytes = math.ceil(len(data_in) / symbols)
padded_data = data_in.ljust(symbol_bytes * symbols, b'\0')
field = pyerasure.finite_field.Binary8()
encoder = pyerasure.Encoder(field, symbols, symbol_bytes)
encoder.set_symbols(padded_data)
generator = pyerasure.generator.RSCauchy(field, symbols)
fragments = []
for idx in range(symbols + parity):
if encoder.rank > idx:
symbol = encoder.symbol_data(idx)
fragments.append((1, idx, symbol))
else:
coefficients, index = generator.generate()
symbol = encoder.encode_symbol(coefficients)
fragments.append((0, index, bytes(symbol)))
return fragments
# Decoding fragments
def decoding_fragments(fragments, symbols):
field = pyerasure.finite_field.Binary8()
symbol_bytes = math.ceil(len(fragments[0][2]) / symbols)
decoder = pyerasure.Decoder(field, symbols, symbol_bytes)
generator = pyerasure.generator.RSCauchy(field, symbols)
for systematic, index, symbol in fragments:
if systematic:
decoder.decode_systematic_symbol(bytearray(symbol), index)
else:
coefficients = generator.generate_specific(index)
decoder.decode_symbol(bytearray(symbol), bytearray(coefficients))
if decoder.is_complete():
return decoder.block_data().rstrip(b'\0')
return 'Cannot decode'
The encoding_fragments
function output a list of tuples consisting of 3 elements:
- Systematic/parity symbol
- Index
- Symbol bytes
I can decode the message for all combinations of 4 symbols except when using systematic symbols 0, 2, 3 and parity symbol 1. Below is an example of the combination of symbols that cannot be decoding. The example contains the message b"This messages will never be lost".
[(1, 0, b'This mes'), (1, 2, b'll never'), (1, 3, b' be lost'), (0, -1, b'`}>\xb25\r\xf1g')]
I have been unable to figure out why this occurs and if there is a problem with my code. I hope someone can help me figure out how to overcome this problem.
Metadata
Metadata
Assignees
Labels
No labels