#if 0 Shamir Sharing Warning!! We use the stock random number generator. You must replace it if you really want to keep a secret!! 67 is prime and 67^4>2^24. We use the field of integers modulo 67. We want to produce k<67 versions of a secret so that we may reconstruct the message when q (0 and libraries in some systems claiming to be ANSI C! static ldiv_t ldiv(long a, long b) {ldiv_t A; A.quot = a/b; A.rem = a % b; return A;} #endif #define N 67 #include #include #include typedef unsigned long u25 /* 32 bits */; typedef unsigned char uc; static char mt[N][N], dt[N]; static void it(void){int i, j; for(i=0; i= (u25)N*N*N*N) printf("Foul value\n"); if(quor > dis || dis >= N) printf("Committee size must not exceed distribution and " "distribution must be less than N\n"); {ldiv_t A = ldiv(sec, N), B = ldiv(A.quot, N), C = ldiv(B.quot, N); char a[4]; a[3] = A.rem; a[2] = B.rem; a[1] = C.rem; a[0] = C.quot; {int k; for(k = 0; k<4; ++k) {char coef[quor]; coef[0] = a[k]; {int m; for(m = 1; m=0; --m) q = M(coef[m] + mt[q][n] - N); w[n-1][k] = q;}}}}}} void sj(int d, int Q, int q[Q]) {char dx[d][4]; split((u25)12345678, Q, d, dx); printf("The %d shares; quorum = %d:\n", d, Q); {int i, j; for(i=0; i