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

Symbols other than 8 bit #12

Closed noah-jones closed 4 years ago

noah-jones commented 7 years ago

Hi, I would like to use an alphabet of 2^5 possible symbols (base32 encoding) for my message and code. I tried setting c_exp to 5 and get the following error:

>>> rs = reedsolo.RSCodec(nsym=2, nsize=8, c_exp=5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/reedsolo-0.5-py3.4-linux-x86_64.egg/reedsolo.py", line 756, in __init__
    init_tables(prim, generator, c_exp)
  File "/usr/local/lib/python3.4/dist-packages/reedsolo-0.5-py3.4-linux-x86_64.egg/reedsolo.py", line 201, in init_tables
    gf_exp[i] = x # compute anti-log for this value and store it in a table
ValueError: byte must be in range(0, 256)

I want to get something like a flight code (length 8 digits/characters) with error correction. Has anyone tried using different symbols? Is it possible using the base library instead of the hight level API? Thanks

lrq3000 commented 7 years ago

Yes it should work with the latest version here:

https://github.com/lrq3000/reedsolomon

There is also various unit tests with different fields orders, so this case should be covered without any problem.

These changes to support different fields should be merged in this repo with PR #11 (but @tomerfiliba seems to be away currently...).

lrq3000 commented 6 years ago

BTW just to precise, the support for other Galois fields was supported already by the core code here, but not the high level API because I forgot to automatically manage the refresh of the data structures. This is fixed in the latest version in #11 and several users reported it works fine :-)

lrq3000 commented 4 years ago

Fixed with the merge of #11

ovgeorge commented 3 years ago

I'm using c_exp=2 and getting and error, is this how it supposed to work?

Traceback (most recent call last):
  File "encoding_test.py", line 6, in <module>
    rsc = RSCodec(nsym=2, nsize=nsize, c_exp=2)
  File "/Users/george/.pyenv/versions/3.7.9/lib/python3.7/site-packages/reedsolo.py", line 865, in __init__
    self.gf_log, self.gf_exp, self.field_charac = init_tables(prim, generator, c_exp)
  File "/Users/george/.pyenv/versions/3.7.9/lib/python3.7/site-packages/reedsolo.py", line 293, in init_tables
    x = gf_mult_noLUT(x, generator, prim, field_charac+1)
  File "/Users/george/.pyenv/versions/3.7.9/lib/python3.7/site-packages/reedsolo.py", line 387, in gf_mult_noLUT
    if prim > 0 and x & field_charac_full: x = x ^ prim # GF modulo: if x >= 256 then apply modular reduction using the primitive polynomial (we just substract, but since the primitive number can be above 256 then we directly XOR).
TypeError: '>' not supported between instances of 'list' and 'int'