tomerfiliba-org / reedsolomon

⏳🛡 Pythonic universal errors-and-erasures Reed-Solomon codec to protect your data from errors and bitrot. Includes a future-proof zero-dependencies pure-python implementation 🔮 and an optional speed-optimized Cython/C extension 🚀
http://pypi.python.org/pypi/reedsolo
Other
358 stars 86 forks source link

How to correct errors with `creedsolo` (`2.1.2b1`)? #70

Open vytas7 opened 1 year ago

vytas7 commented 1 year ago

Hello! I'm having issues with using the cythonized creedsolo, encoding and checking seems to work great, but my attempt to correct errors results in a ReedSolomonError:

FAILED test.py::test_reed_solomon - creedsolo.creedsolo.ReedSolomonError: Too many (or few) errors found by Chien Search for the errata locator polynomial!

(It works as expected with the pure Python version.)

My test case used:

# Pure Python works as expected
# import reedsolo as rs
import creedsolo as rs

DATA = b'123456789abcdef\n' * 64

def test_reed_solomon():
    prim = rs.find_prime_polys(c_exp=11, fast_primes=True, single=True)[0]
    rs.init_tables(c_exp=11, prim=prim)

    gen = rs.rs_generator_poly_all(1024+16)
    encoded = rs.rs_encode_msg(DATA, 16, gen=gen[16])

    encoded[3] = ord('7')
    encoded[100] = ord('!')

    assert not rs.rs_check(encoded, 16)
    _, _, errata_pos = rs.rs_correct_msg(encoded, 16)
    assert set(errata_pos) == {3, 100}

FWIW, I used the current Git master @ 23b8eab

pip install . --config-setting="--build-option=--cythonize"
lrq3000 commented 1 year ago

Hello, it seems your mkssage is incomplete. Unfortunately I am not going to be able to study your issue for the coming 2 weeks as I will be away. If you did not try yet, maybe you can try the very latest version using pip install reedsolo --pre, as this will install the v2 branch of reedsolo that uses a significantly updated creedsolo module.

21 juil. 2023 09:24:36 Vytautas Liuolia @.***>:

Hello! I'm having issues with using the cythonized creedsolo, encoding and checking seems to work great, but my attempt to correct errors results in:

— Reply to this email directly, view it on GitHub[https://github.com/tomerfiliba-org/reedsolomon/issues/70], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAIRFXWCMEHZSSNOPKZICUTXRIVDJANCNFSM6AAAAAA2SOLKHE]. You are receiving this because you are subscribed to this thread.[Image de pistage][https://github.com/notifications/beacon/AAIRFXQTWSPRBL6UQYPCU6TXRIVDJA5CNFSM6AAAAAA2SOLKHGWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHGYM2KIU.gif]

vytas7 commented 1 year ago

Thanks @lrq3000! No worries, I was just looking for some Reed-Solomon library for a hobby project :slightly_smiling_face: Not urgent at all.

I did use the latest Git master to start with.

Not sure if it is me misunderstanding something, or it is a real bug (related to the recent Cython 3.0.0 release?).

lrq3000 commented 1 year ago

No I meant your issue here was incomplete when I first saw it, only the first sentence appeared ;-)

Ok so creedsolo is more optimized for GF(2⁸). For other fields, it may work, but it may also fail. I’ll have to have a second look, here you are using GF(2^11) so that’s likely why it’s failing.

Please try using the RSCodec class instead of using the low level functions, as this class tries to handles the tricky technicals, and especially with creedsolo, there are more hoops to go through to be compatible with all fields since creedsolo tries to be as optimized as possible, which is at the expense of flexibility and less generalizability.