The Laws of Cryptography:
Generate Multiplication Tables

by Neal R. Wagner

NOTE: This site is obsolete. See book draft (in PDF):

The following Java program uses the slow GF(28) multipy function to generate two tables needed for fast multiplication: a table of all powers of the generator 0x03, and the inverse table. (The tables in the main section had a few extra frills inserted by hand.)

```// FFMultTables: create the arrays E and L, write html versions of them
public class FFMultTables {
public byte[] E = new byte[256];
public byte[] L = new byte[256];
private String[] dig = {"0","1","2","3","4","5","6","7",
"8","9","a","b","c","d","e","f"};
public byte FFMul(byte a, byte b) {
byte aa = a, bb = b, r = 0, t;
while (aa != 0) {
if ((aa & 1) != 0)
r = (byte)(r ^ bb);
t = (byte)(bb & 0x80);
bb = (byte)(bb << 1);
if (t != 0)
bb = (byte)(bb ^ 0x1b);
aa = (byte)((aa & 0xff) >> 1);
}
return r;
}

public String hex(byte a) {
return dig[(a & 0xff) >> 4] + dig[a & 0x0f];
}

public String hex(int a) {
return dig[a];
}

byte x = (byte)0x01;
int index = 0;
E[index++] = (byte)0x01;
for (int i = 0; i < 255; i++) {
byte y = FFMul(x, (byte)0x03);
E[index++] = y;
// System.out.print(hex(y) + " ");
x = y;
}
}

int index;
for (int i = 0; i < 255; i++) {
L[E[i] & 0xff] = (byte)i;
}
}

public void printE() {
System.out.print("<table border><tr><td></td>");
for (int i = 0; i < 16; i++)
System.out.print("<th>" + hex(i) + "</th>");
System.out.println("</tr>");
for (int i = 0; i < 256; i++) {
if (i%16 == 0)
System.out.print("<tr><th> " + hex(i/16) + " </th>");
System.out.print("<td> " + hex(E[i]) + " </td>");
if (i%16 == 15) System.out.println("</tr>");
}
System.out.println("</table>");
}

public void printL() {
System.out.print("<table border><tr><td></td>");
for (int i = 0; i < 16; i++)
System.out.print("<th>" + hex(i) + "</th>");
System.out.println("</tr>");
for (int i = 0; i < 256; i++) {
if (i%16 == 0)
System.out.print("<tr><th> " + hex(i/16) + " </th>");
if (i == 0)
System.out.print("<td>  </td>");
else
System.out.print("<td> " + hex(L[i]) + " </td>");
if (i%16 == 15) System.out.println("</tr>");
}
System.out.println("</table>");
}

public static void main(String[] args) {
FFMultTables ffm = new FFMultTables();