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

Size check not accurate #2

Closed keestr closed 3 years ago

keestr commented 3 years ago

Hi,

First of all thanks for your efforts creating this library.

A small remark however: IMHO the check: if (toEncode.Length >= this.field.Size) on line 64 of the ReedSolomonEncoder should have a > instead of a >=.

The following reasoning leads me to this: The data size representing 128 message bytes + 32 ecBytes =160 data bytes and can be encoded with the GenericGF AZTEC_DATA_8, same holds for 223 message bytes + 32 error correction bytes = 255 bytes of data. However, a message of 224 bytes is now not supported, although I think it can be represented in 256 bytes of data.

What is your opinion on this? Is it possible to store 224 bytes and 32 ecBytes using GenericGF AZTEC_DATA_8?!

Sonic-The-Hedgehog-LNK1123 commented 3 years ago

The check is correct, the maximum number of data + ecc symbols is always one less than the field size.

With 8 bits, the max is 255 symbols (2^8 - 1) With 12 bits, the max is 4095 symbols (2^12 - 1) With 16 bits, the max is 65535 symbols (2^16 - 1) And so on.

Commonly used (n,k) Reed-Solomon codes are (255,223), (255,239), (255,251) and so on. Notice the 255 in the above codes? That is the max size of a 8-bit/symbol RS code, there is a whole mathematical reason behind that limit.

Your 224 + 32 example exceeds that limit by 1.

keestr commented 3 years ago

Hi! I see! It works now! Thank you for the extensive response and great library!