/**************************** Encoder ****************************/ #include #include #include #define mm 4 /* RS code over GF(2**4) - change to suit */ #define nn 15 /* nn=2**mm -1 length of codeword */ #define tt 3 /* number of errors that can be corrected */ #define kk 9 /* kk = nn-2*tt */ int pp [mm+1] = { 1, 1, 0, 0, 1} ; /* specify irreducible polynomial coeffts */ /*int alpha_to [nn+1], index_of [nn+1], gg [nn-kk+1] ;*/ /****Setting Up The Galois Fields and Indices*******/ /* In practice they are generated 'on the fly' depending on the 'packet' sizes and parity bits which are defined earlier. We are using a fixed packet size of 9 with 6 parity bits and thus these are the Galois Fields and Indices */ int gg[] = {6,9,6,4,14,10,0,0,0,0,0,0,0,0,0,0}; int alpha_to[] = {1,2,4,8,3,6,12,11,5,10,7,14,15,13,9,0}; int index_of[] = {-1,0,1,4,2,8,5,10,3,14,9,7,6,13,11,12}; int recd [nn], data [kk], bb [nn-kk] ; void encode_rs(); /********Driver Program*******/ main(int argc, char **argv) { int count = 0; /*****Get User Input******/ if(argc!=10) { printf("Usage: a.out d1 d2 d3 d4 d5 d6 d7 d8 d9\n"); printf("Where d1, d2, ..., etc. are the integer data values (0-15)\n"); printf("Unix Example: a.out 1 2 3 4 5 6 7 8 9 [enter]\n"); printf(" DOS Example: rs-encode 1 2 3 4 5 6 7 8 9 [enter]\n"); exit(0); } /****Convert ascii string to a float******/ for(count=0; count =0; i--) { feedback = index_of[data[i]^bb[nn-kk-1]] ; if (feedback != -1) { for (j=nn-kk-1; j>0; j--) { if (gg[j] != -1) { bb[j] = bb[j-1]^alpha_to[(gg[j]+feedback)%nn] ; } else { bb[j] = bb[j-1] ; } } bb[0] = alpha_to[(gg[0]+feedback)%nn] ; } else { for (j=nn-kk-1; j>0; j--) { bb[j] = bb[j-1] ; } bb[0] = 0 ; } } }