static Aes()
{
var encTable = _tables[0];
var decTable = _tables[1];
var sbox = encTable[4];
var sboxInv = decTable[4];
uint x, xInv;
uint[] d = new uint[256];
uint[] th = new uint[256];
uint x2, x4, x8, s;
uint tEnc, tDec;
// Compute double and third tables
for (uint i = 0; i < 256; i++)
{
d[i] = i << 1 ^ (i >> 7) * 283;
th[d[i] ^ i] = i;
}
for (x = xInv = 0; sbox[x] == 0; x ^= (x2 != 0 ? x2 : 1), xInv = (th[xInv] != 0 ? th[xInv] : 1))
{
// Compute sbox
s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
s = s >> 8 ^ s & 255 ^ 99;
sbox[x] = s;
sboxInv[s] = x;
// Compute MixColumns
x8 = d[x4 = d[x2 = d[x]]];
tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
tEnc = d[s] * 0x101 ^ s * 0x1010100;
for (int i = 0; i < 4; i++)
{
encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >> 8;
decTable[i][s] = tDec = tDec << 24 ^ tDec >> 8;
}
}
//// Compactify. Considerable speedup on Firefox.
//for (int i = 0; i < 5; i++) {
// encTable[i] = encTable[i].slice(0);
// decTable[i] = decTable[i].slice(0);
//}
}