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
352 stars 86 forks source link

number of errors seen #17

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

Maybe you can extend the api so that decode() returns a tuple: (data, n_errors_seen) ? That way one can anticipate by lowering baudrates and such.

lrq3000 commented 4 years ago

Technically, it's easy, in rs_correct_msg just add err_pos at the end of the return. Then rs_correct_msg will return the list of erasures and error positions combined, and you can just check its length.

lrq3000 commented 4 years ago

I thought about it, and since my latest PR was just merged today, and it's already breaking backward compatibility, I decided to implement your request, as I think it's very useful indeed to return the location of errors.

You can pip install --upgrade reedsolo to enjoy the new implementation :-) I also added an example in the readme.

lrq3000 commented 4 years ago

Here is a concrete example:

>>> rsc = RSCodec(12)  # using 2 more ecc symbols (to correct max 6 errors or 12 erasures)
>>> rsc.encode(b'hello world')
b'hello world?Ay\xb2\xbc\xdc\x01q\xb9\xe3\xe2='
>>> rsc.decode(b'hello worXXXXy\xb2XX\x01q\xb9\xe3\xe2=')[0]         # 6 errors - ok, but any more would fail
b'hello world'
>>> rsc.decode(b'helXXXXXXXXXXy\xb2XX\x01q\xb9\xe3\xe2=', erase_pos=[3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16])[0]  # 12 erasures - OK
b'hello world'

# Checking
>> rsc.check(b'hello worXXXXy\xb2XX\x01q\xb9\xe3\xe2=')  # Tampered message will return False
[False]
>> rmes, rmesecc, errata_pos = rsc.decode(b'hello worXXXXy\xb2XX\x01q\xb9\xe3\xe2=')
>> rsc.check(rmesecc)  # Corrected message will return True
[True]
>> print('Number of detected errors and erasures: %i, their positions: %s' % (len(errata_pos), list(errata_pos)))
Number of detected errors and erasures: 6, their positions: [16, 15, 12, 11, 10, 9]
ghost commented 4 years ago

cool! thanks!

On Sun, Mar 1, 2020 at 10:09 PM Stephen Karl Larroque < notifications@github.com> wrote:

I thought about it, and since my latest PR was just merged today, and it's already breaking backward compatibility, I decided to implement your request, as I think it's very useful indeed to return the location of errors.

You can pip install --upgrade reedsolo to enjoy the new implementation :-) I also added an example in the readme.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tomerfiliba/reedsolomon/issues/17?email_source=notifications&email_token=AAYRFOAPLTGLIJ34DNWWUWDRFLFIJA5CNFSM4KINZUW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENNLAZY#issuecomment-593145959, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYRFOBDJ3KSIKQYOS4NFFDRFLFIJANCNFSM4KINZUWQ .

-- www.vanheusden.com www.slimwinnen.nl www.winnenmetbitcoin.nl

www.hackerspace-gouda.nl www.slimmetvalutahandelen.nl

lrq3000 commented 4 years ago

You're welcome :-) Please however note that if the number of errors/erasures exceed the singleton bound, the decoder may return 0 error, thus it is not a reliable way to detect if a message was tampered, please use a checksum instead (but checksums can't give you the number of bits that were tampered, so you may have to use both for a reliable adaptive bitrate algo).