I'm into developing code to do arithmetic in Galois field gf(2^8) and I think I'm getting wrong results on multiplication operations.
private static byte Multiply(byte a, byte b)
{
byte result = 0;
while (b != 0)
{
if ((b & 1) != 0)
{
result ^= a;
}
a <<= 1;
b >>= 1;
}
return result;
}
The result for Multiply(1, 2) gives the correct value of 2 but Multiply(240, 249) gives me 112 instead of the expected 148.
Now I'm not sure if this value is good or not with Russian Peasant Multiplication.
Maybe there's another algorithm that gives correct results?