public static Polinom PowerGF256(Polinom a, Polinom b, byte f) { byte c = 1; byte bc = b.coef; while (bc > 0) { if (bc % 2 == 1) { c = MultGF256(a, b, f).coef; } a = MultGF256(a, a, f); bc = (byte)(bc >> 1); } return(new Polinom(c)); }
public static Polinom MultGF256(Polinom a, Polinom b, byte f) { byte t = 0, mask = 1; byte ac = a.coef, bc = b.coef; for (int i = 0; i < 8; i++) { if ((bc & mask) != 0) { t = (byte)(t ^ ac); } if ((ac & 128) != 0) { ac = (byte)(ac << 1); } else { ac = (byte)((ac << 1) ^ f); } mask = (byte)(mask << 1); } return(new Polinom(t)); }