Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compatible with matlab's rsenc/rsdec; only deal with n=255. #2

Closed
felix021 opened this issue Mar 29, 2013 · 8 comments
Closed

Not compatible with matlab's rsenc/rsdec; only deal with n=255. #2

felix021 opened this issue Mar 29, 2013 · 8 comments

Comments

@felix021
Copy link

Hey buddy, as is said in the mail, I tried to improve this package, but encountered an error in the decoder. The improvements to the encoder may help, so I send it to you, hoping that you (or some one else) can (easily) fix it.

p.s. Source code is not permitted to be attached here.

@tomerfiliba
Copy link
Collaborator

as i explained in the readme, i don't understand enough math to patch this myself. if you can send a working patch, i'll happily incorporate it in, but i can't do it (nor do i have the time) on my own.

in order to submit a patch, click "fork" on github repo, which will create a separate repo on which you can work. when you're done, create a pull request and send me the patch. it's very easy to do on github. see https://help.github.com/articles/using-pull-requests

@shuffle2
Copy link

I have also noticed that reedsolo library is not working correctly. Codewords of size 9 (5 data+4 parity) and 62 (30 data+32 parity) seem to work ok. But for size 248 (216 data+32 parity), it fails. According to the readme this should still work, as it's under 255, no?
You can compare results with another library I've found to work on the large codeword size, if interested: http://rscode.sourceforge.net/ (requires NPAR=32 for the 216+32 configuration).

For me, I can just use rscode C library. But I thought I'd document the issue here.

edit:
for example, here is a log of codeword being decoded/corrected by rscode: http://pastie.org/9397876
reedsolo will just except with "Could not locate error" for this input data.

@morefigs
Copy link

Where exactly is it failing for you shuffle2? In my experience I could only encode 7-bit strings but could encode 8-bit (i.e. up to 255) byte arrays. Eg:

str_with_8_bit_chars = 'å˜ýþ'
RSCodec.encode(str_with_8_bit_chars)    # fails

str_as_bytearray = bytearray(str_with_8_bit_chars)
RSCodec.encode(str_as_bytearray)    # works

This is because the library attempts to convert any string into a 7-bit bytearray, but ignores it if it is already a bytearray.

Hope that helps with your issue.

@shuffle2
Copy link

This is the same input codeword as previous pastie:

Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from reedsolo import *
>>> codeword=open('codeword_248.bin','rb').read()
>>> import binascii
>>> binascii.hexlify(codeword)
b'430949cd403e238bc48ac5906474c30be37479a516ad5b2fc8867a18d3d2c689e1c9b76175f745fc23d8f5f1ab2d732ee226527f9cb7335596311a7c3e8d61e28565fb32fb77aceb2062
47c8710ba154a36e1f31c4953abd4ec1bea560c8254d9c7d9e82709cd8cf5a830b2fbff21e60dc619e4aff7f0ad40948dc5a2478c378d37868c78704fec69cb4007bb8dcc3b8d44b680691
2de45cc221435c1eea73588758302b6753a9f6d82f5cc774312f28803e67cd421c17bf721bbd231f8584ec6c9e32748de78104c78996cd56a08a390e73e75ad4ab902f6d7eeb8858a8e7c4
d215a52687c3c4c5e04aeb8f997bdd8a284b82aa31b49618'
>>> RSCodec(32).decode(codeword)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python34\lib\site-packages\reedsolo.py", line 251, in decode
    dec.extend(rs_correct_msg(chunk, self.nsym))
  File "c:\Python34\lib\site-packages\reedsolo.py", line 213, in rs_correct_msg
    raise ReedSolomonError("Could not locate error")
reedsolo.ReedSolomonError: Could not locate error
>>> RSCodec(32).decode(bytearray(codeword))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python34\lib\site-packages\reedsolo.py", line 251, in decode
    dec.extend(rs_correct_msg(chunk, self.nsym))
  File "c:\Python34\lib\site-packages\reedsolo.py", line 213, in rs_correct_msg
    raise ReedSolomonError("Could not locate error")
reedsolo.ReedSolomonError: Could not locate error
>>> binascii.hexlify(RSCodec(32).encode(codeword[:216]))
b'430949cd403e238bc48ac5906474c30be37479a516ad5b2fc8867a18d3d2c689e1c9b76175f745fc23d8f5f1ab2d732ee226527f9cb7335596311a7c3e8d61e28565fb32fb77aceb2062
47c8710ba154a36e1f31c4953abd4ec1bea560c8254d9c7d9e82709cd8cf5a830b2fbff21e60dc619e4aff7f0ad40948dc5a2478c378d37868c78704fec69cb4007bb8dcc3b8d44b680691
2de45cc221435c1eea73588758302b6753a9f6d82f5cc774312f28803e67cd421c17bf721bbd231f8584ec6c9e32748de78104c78996cd56a08a390e73e75ad4ab902f81dae140d009d66f
4fd563d944b519db601a89bf52f73a8a55505331b41e4381'
>>> binascii.hexlify(RSCodec(32).encode(codeword[:216])[216:])
b'81dae140d009d66f4fd563d944b519db601a89bf52f73a8a55505331b41e4381'
>>> binascii.hexlify(codeword[216:])
b'6d7eeb8858a8e7c4d215a52687c3c4c5e04aeb8f997bdd8a284b82aa31b49618'

It should decode correctly with errors in one byte and no erasures.

@shuffle2
Copy link

At this point, I'm seeing strange behavior with rscode as well :(
If I decode the codeword, it will correct one byte and indicate success. If I try to decode this "corrected" value, it will fail. If I take the "corrected" bytes and re-encode, a different parity buffer is generated (also differs from the one generated by reedsolo).

Nothing makes sense! :(

@morefigs
Copy link

Shit, another programmer lost to reed solomon madness...

@shuffle2
Copy link

mmmph, my comments here can be ignored. Turns out I was generating some data incorrectly, and the codewords with higher parity:data ratio could of course correct my bad data, while the larger codewords had too much bad data (and I wasn't using erasures).
Works now :)
Related: I do wish using erasures with this library were more obvious though - didn't realize it was supported until I started inserting debug print()s in the code.

@lrq3000
Copy link
Collaborator

lrq3000 commented Jul 29, 2015

If you still experience an issue, please try the new release, it has been thoroughly unit tested, or else if it's ok now, please close this thread :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants