1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| int main ()
{
int NW;
int i;
FILE *pt, *pti;
char *nom8 = "gflog8.h";
char *nomi8 = "gfilog8.h";
char *nom256 = "gflog256.h";
char *nomi256 = "gfilog256.h";
char *nom65536 = "gflog65536.h";
char *nomi65536 = "gfilog65536.h";
//compute gflog8 and gfilog8
pt = fopen(nom8,"wt");
fputs ("unsigned short gflog8[16]={",pt);
pti = fopen(nomi8, "wt");
fputs ("unsigned short gfilog8[16]={",pti);
NW = 16;
i = compute_log(NW);
//gflog[0] doesn't exist
fprintf(pt, "-1, ", *(gflog++));
fprintf(pti, "%u, ", *(gfilog++));
for(i=1;i<NW-1;i++)
{
fprintf(pt, "%u, ", *(gflog++));
fprintf(pti, "%u, ", *(gfilog++));
}
fprintf(pt, "%u};", *(gflog));
//gfilog[15] doesn't exist
fprintf(pti, "-1};", *(gfilog));
fclose(pt);
fclose(pti);
return 1;
}
//_______________________________________________________________________________________________________________
//_______________________________________________________________________________________________________________
//_______________________________________________________________________________________________________________
//_______________________________________________________________________________________________________________
// compute_log compute log and antilog chart,
//they define + and - in Galois field
int compute_log(int NW)
{
unsigned int b, log, x_to_w, prim_poly;
int w, i;
w = (int) (log10 ( (double) NW) / log10(2));
switch(w) {
case 4: prim_poly = prim_poly_4; break;
case 8: prim_poly = prim_poly_8; break;
case 16: prim_poly = prim_poly_16; break;
default: return -1;
}
x_to_w = 1 << w;
gflog = (unsigned short *) malloc (sizeof(unsigned short) * x_to_w);
if(gflog == NULL)
{
fprintf(stderr,"Allocation gflog impossible \n");
exit(EXIT_FAILURE);
}
gfilog = (unsigned short *) malloc (sizeof(unsigned short) * x_to_w);
if(gfilog == NULL)
{
fprintf(stderr,"Allocation gfilog impossible \n");
exit(EXIT_FAILURE);
}
b = 1;
gflog[0] = -NW;
gfilog[0] = 1;
for(i=1;i<NW;i++)
{
gfilog[i] = gfilog[i-1]*2;
if(gfilog[i]>=256) gfilog[i] = gfilog[i] ^ 301;
gflog[gfilog[i]]=i;
if(gflog[i]<10)
{
//gflog[i] = "00" + gflog[i];
unsigned short *str;
str = NULL;
strcpy((char*)str, "00");
strcat((char *)str, (char *)gflog[i]);
//gflog[i] = "000" ^ gflog[i];
}
}
return 0;
} |
Partager