Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReedSolomonEC.cs
1using System;
2
4{
9 public class ReedSolomonEC
10 {
11 private readonly GF256Px generatorPolynomial;
12 private readonly int nrCorrectionCodeWords;
13
20 public ReedSolomonEC(int NrCorrectionCodeWords)
21 {
22 if (NrCorrectionCodeWords <= 0)
23 throw new ArgumentException("Number of correction code words must be positive.", nameof(NrCorrectionCodeWords));
24
25 GF256Px P = new GF256Px(new byte[] { 1, 1 }); // X-1 = X-α^0
26 int i = 0;
27
28 while (++i < NrCorrectionCodeWords)
29 P = P.Multiply(new GF256Px(new byte[] { 1, GF256.PowerOf2Table[i] })); // X-α^i
30
31 this.generatorPolynomial = P;
32 this.nrCorrectionCodeWords = NrCorrectionCodeWords;
33 }
34
38 public GF256Px GeneratorPolynomial => this.generatorPolynomial;
39
45 public byte[] GenerateCorrectionCode(byte[] Message)
46 {
47 byte[] C = new byte[Message.Length + this.nrCorrectionCodeWords];
48 Message.CopyTo(C, 0);
49
50 GF256Px M = new GF256Px(C);
51 GF256Px Resiue = M.Residue(this.generatorPolynomial);
52
53 return Resiue.Coefficients;
54 }
55 }
56}
Class representing arithmentic over the Galois Field GF(256) ~ ~ Z2[x]/P(x) over some irreducible pol...
Definition: GF256.cs:15
static byte[] PowerOf2Table
Power of 2 table.
Definition: GF256.cs:45
Polynomial over GF(256), where coefficients are defined as bytes in a byte array (Least significant b...
Definition: GF256Px.cs:11
GF256Px Multiply(GF256Px P)
Multiplies the polynomial with the polynomial defined by P .
Definition: GF256Px.cs:39
GF256Px Residue(GF256Px Divisor)
Calculates the residue of the polynomial devision of this polynomial, with a divisor in Divisor .
Definition: GF256Px.cs:59
byte[] Coefficients
Polynomial coefficients.
Definition: GF256Px.cs:30
Implements Reed-Solomon Error Correction using polynomial division over GF(256)[x].
ReedSolomonEC(int NrCorrectionCodeWords)
Implements Reed-Solomon Error Correction using polynomial division over GF(256)[x].
byte[] GenerateCorrectionCode(byte[] Message)
Computes the Error Correction code for a message.
GF256Px GeneratorPolynomial
Generator polynomial.