Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GF256Px.cs
1using System;
2
4{
10 public class GF256Px
11 {
12 private readonly byte[] coefficients;
13 private readonly int degree;
14
21 public GF256Px(byte[] Coefficients)
22 {
23 this.coefficients = Coefficients;
24 this.degree = this.coefficients.Length - 1;
25 }
26
30 public byte[] Coefficients => this.coefficients;
31
40 {
41 byte[] C = new byte[this.degree + P.degree + 1];
42 int i, j;
43
44 for (i = 0; i <= P.degree; i++)
45 {
46 for (j = 0; j <= this.degree; j++)
47 C[i + j] ^= GF256.Multiply(this.coefficients[j], P.coefficients[i]);
48 }
49
50 return new GF256Px(C);
51 }
52
59 public GF256Px Residue(GF256Px Divisor)
60 {
61 if (this.degree < Divisor.degree)
62 return this;
63
64 if (Divisor.coefficients[0] != 1)
65 throw new NotSupportedException("Leading coefficien must be 1."); // Will always be one if only generator polynomials are used.
66
67 byte[] C = (byte[])this.coefficients.Clone();
68 int i, c, j;
69 byte b;
70
71 c = this.degree - Divisor.degree;
72 for (i = 0; i <= c; i++)
73 {
74 b = C[i];
75 if (b == 0)
76 continue;
77
78 C[i] = 0;
79 for (j = 1; j <= Divisor.degree; j++)
80 C[i + j] ^= GF256.Multiply(b, Divisor.coefficients[j]);
81 }
82
83 byte[] Residue = new byte[Divisor.degree];
84 Array.Copy(C, c + 1, Residue, 0, Divisor.degree);
85
86 return new GF256Px(Residue);
87 }
88
89 }
90}
Class representing arithmentic over the Galois Field GF(256) ~ ~ Z2[x]/P(x) over some irreducible pol...
Definition: GF256.cs:15
static byte Multiply(byte x, byte y)
Multiplies two numbers
Polynomial over GF(256), where coefficients are defined as bytes in a byte array (Least significant b...
Definition: GF256Px.cs:11
GF256Px(byte[] Coefficients)
Polynomial over GF(256), where coefficients are defined as bytes in a byte array (Least significant b...
Definition: GF256Px.cs:21
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