tomerfiliba-org/reedsolomon

Bytes vs. Symbols

Opened this issue · 1 comments

Hi,

I am a bit confused about the theory vs. the implementation of the reedsolo.
Theoretically, Reed-Solomon code with two ECC symbols should correct one symbol error.

This behavior is not what is happening with reedsolo. When I create single symbol correcting RSCodec for GF(2^16), i.e., two symbols of ECC, encode the message, and then corrupt first two bytes in it, the decoder fails with "Decoding failed: Too many errors to correct". Which is not how it supposed to behave: with 16-bit symbol, any 2-byte symbol-aligned corruption should be corrected (as those two bytes correspond to one 16-bit symbol).

What am I missing here? Is there any parameter I should define?
I am using reedsolo v2.0.13.

Here is the code that I am using to test this behavior:

import reedsolo as rs

# Initialize the tables with a primitive polynomial for GF(65536)
rs.init_tables(prim=0x18BB7, c_exp=16)

ecc_symbols = 2
codeword_length = 2**16 -1
# Create a Reed-Solomon codec with 16-bit symbols (GF(65536)) and 8 error correction symbols
codec = rs.RSCodec(nsym=ecc_symbols, c_exp=16, prim=0x18BB7, nsize=codeword_length)

# Original message (64 bytes or 32 symbols)
message = 'a'*(64)
print(f"len(message): {len(message)}")

# Encode the message
encoded_message = codec.encode(message)
print("Encoded message:", encoded_message)

# Introduce errors (corrupt two bytes, i.e., one symbol error)
corrupted_message = encoded_message
for i in range(2):
    corrupted_message[i] ^= 0x01 

print("Corrupted message:", corrupted_message)
# Decode the corrupted message
try:
    mes, mes_ecc, err_loc = codec.decode(corrupted_message)
    print("Decoded message:", mes)
    print("Error location:", err_loc)
    print("Message w/ ECC:", mes_ecc)
except rs.ReedSolomonError as e:
    print("Decoding failed:", e)

+1