//构造GF(2^8)上的对数表和反对数表 publicvoid generateLogTable() ...{ int i, j;
alog[0] =1; for (i =1; i <256; i++) ...{ j = (alog[i-1] <<1) ^ alog[i-1]; if ((j &0x100) !=0) j ^=0x11B; //0x11B即本原多项式x^8+x^4+x^3+x+1 alog[i] = j; }
log[0] = log[1] =0; for (i =1; i <255; i++) log[alog[i]] = i; }
//GF(2^8)上的乘法运算,查表实现 publicint mul(int A, int B) ...{ if (A ==0|| B ==0) return0; else return alog[(log[A]+log[B])%255]; }
//GF(2^8)上的除法运算,查表实现 publicint div(int A, int B) ...{ if (A ==0) return0; elseif (B ==0) ...{ System.err.println("divide by zero exception"); return-1; } else...{ if ((log[A]-log[B]) <0) return alog[(log[A]-log[B]+255)%255]; else return alog[(log[A]-log[B])%255]; } }