Sonic-The-Hedgehog-LNK1123 / ReedSolomon

A .NET implementation of the Reed-Solomon algorithm, supporting error, erasure and errata correction
Apache License 2.0
14 stars 1 forks source link

Valid primitive polynomials #4

Open andrzejlisek opened 3 years ago

andrzejlisek commented 3 years ago

In issue https://github.com/Sonic-The-Hedgehog-LNK1123/ReedSolomon/issues/3 there is provided primitive polynomial for every number of bits between 2 and 30. The polynomial I found using https://www.wolframalpha.com/input/?i=finite+field+of+order+65536 using the first primitive polynomial for each power of 2. I found, that providing invalid polynomial (described as integer positive number) causes infinity loop between lines 317 and 325 of https://github.com/Sonic-The-Hedgehog-LNK1123/ReedSolomon/blob/master/ReedSolomon/GenericGFPoly.cs when Encoding is ran.

I am not familiar with Galois field theory and it is difficult for me. It is possible to reliably test if provided polynomial is valid using your and ZXing code? The performance is not important for me, I will accept the brute-force way. For example, I know that, for 8-bit values all polynomials are between 256 and 511, so it is not problem to generate every value between this and test each value. For 16-bit values there are above 2000 valid primitive polynomials of about 65000 possible polynomials, so the best way is generate the list once and store it.

Sonic-The-Hedgehog-LNK1123 commented 3 years ago

The easiest (brute-force) way to check if a polynomial is valid is to check if the first ((Galois field size) - 1) values of the generated Galois field are all unique, if they are, the polynomial is valid, if duplicate values are found, the polynomial is invalid.

This check can take a long time for larger fields.

Because this check is a huge performance hit, it's left out in many implementations. In general, the polynomial is specified in whatever specification you're using.

JessicaMulein commented 2 years ago

I hate to ask, but are we talking about examining the expTable on the GenericGF object? If the implementation is simple, could I ask you to show the non-math experts around? :) I'm looking to generate basically error correction data of original data such that all original data is deleted and the FEC data is divided up into shards, where a required # of shards is needed to reconstruct the data. It would be nice to be able to has some more mental security as I tinker with this process...