/* Author: Pate Williams (c) 1997 Exercise 10.4 "Construct an orthogonal array OA(3, 13, 3)." -Douglas R. Stinson- See "Cryptography: Theory and Practice by Douglas R. Stinson page 325. */ #include long radix_representation(long b, long A, long *a) { long i = 0, q, x = A; q = x / b, a[i] = x - q * b; while (q > 0) i++, x = q, q = x / b, a[i] = x - q * b; return i + 1; } int main(void) { int found; long count = 0, i, j, k, length, p = 3, s; long R[27][3], C[27][3]; printf("R\n"); for (i = 0; i < 27; i++) { length = radix_representation(3, i, R[i]); for (j = length; j < 3; j++) R[i][j] = 0; for (j = 2; j >= 0; j--) printf("%d", R[i][j]); printf(" "); if ((i + 1) % 8 == 0) printf("\n"); } for (i = 0; i < 27; i++) { found = 0; for (j = 2; !found && j >= 0; j--) { found = R[i][j] != 0; if (found) k = j; } if (found) { if (R[i][k] == 1) { for (j = 0; j < 3; j++) C[count][j] = R[i][j]; count++; } } } printf("\nC\n"); for (i = 0; i < count; i++) { for (j = 2; j >= 0; j--) printf("%d", C[i][j]); printf(" "); if ((i + 1) % 8 == 0) printf("\n"); } printf("\nOA(3, 13, 3)\n"); for (i = 0; i < 27; i++) { for (j = 0; j < count; j++) { s = 0; for (k = 2; k >= 0; k--) s += R[i][k] * C[j][k]; s %= p; printf("%d ", s); } printf("\n"); } return 0; }