Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GF256.cs
1using System.Collections.Generic;
2
4{
14 public static class GF256
15 {
16 private readonly static byte[] powersOfTwo;
17 private readonly static byte[] log2;
18
19 static GF256()
20 {
21 SortedDictionary<byte, byte> Inv = new SortedDictionary<byte, byte>();
22 int i, j;
23
24 powersOfTwo = new byte[256];
25
26 for (i = 0, j = 1; i < 256; i++)
27 {
28 powersOfTwo[i] = (byte)j;
29
30 if (i != 255)
31 Inv[(byte)j] = (byte)i;
32
33 j <<= 1;
34 if (j >= 256)
35 j ^= 285; // equal to j-=poly = rest of j/poly as polynomial division
36 }
37
38 log2 = new byte[256];
39 Inv.Values.CopyTo(log2, 1);
40 }
41
45 public static byte[] PowerOf2Table => powersOfTwo;
46
50 public static byte[] Log2Table => log2;
51
58 public static byte Add(byte x, byte y) => (byte)(x ^ y);
59
66 public static byte Subtract(byte x, byte y) => (byte)(x ^ y);
67
74 public static byte Multiply(byte x, byte y) => powersOfTwo[(log2[x] + log2[y]) % 255];
75 }
76}
Class representing arithmentic over the Galois Field GF(256) ~ ~ Z2[x]/P(x) over some irreducible pol...
Definition: GF256.cs:15
static byte[] Log2Table
Log2 table.
Definition: GF256.cs:50
static byte Subtract(byte x, byte y)
Subtracts one number from another
static byte Add(byte x, byte y)
Adds two numbers
static byte[] PowerOf2Table
Power of 2 table.
Definition: GF256.cs:45
static byte Multiply(byte x, byte y)
Multiplies two numbers