Reed-Solomon Error Correction by Hugo Lyppens Example 1: (x4 + x2) + (x2 + 1) =(x4 + 1) 0 - (x4 + x) = (x4 + x) x + x = 0 x - x = 0 Example 2: (x4 + x2) * (x2 + 1) = (x6 + x2) x8 = x6 + x5 + x4 +1 x255 = x0 = 1 Example 3: mov bl,I mov bh,J mov al,[edi+ebx] Listing One /****************************************************** * File: gf256.c -- contains code to construct GF(2^8) and all required * arrays for GF(2^8) arithmetic. * Copyright (c) 1995 by Hugo Lyppens with permission to print in DDJ ******************************************************/ #include "hdr.h" #include "rs.h" #define POL 0x171 /* primitive polynomial used to construct GF(2^8) is: x8 + x6 + x5 + x4 + 1 represented as 101110001 binary */ UBYTE RSG_powers[FIELDSZ]; UBYTE RSG_logarithm[FIELDSZ]; UBYTE RSG_multinv[FIELDSZ]; UBYTE RSG_multiply[FIELDSZ][FIELDSZ]; static UBYTE multiply_func(UBYTE, UBYTE); static UBYTE multinv_func(UBYTE); void RSG_ConstructGaloisField() { int v; UBYTE i, j; v = 1; for(i = 0; ; i++) { RSG_powers[i] = (UBYTE)v; RSG_logarithm[v] = i; v <<=1; // multiply v by alpha and reduce modulo POL if(v & (1<=1; i--) { RSG_genpol.c[i] = RSG_genpol.c[i-1]^multiply(RSG_genpol.c[i], a); } RSG_genpol.c[0] = multiply(a, RSG_genpol.c[0]); } printf("Generator polynomial: "); printpoly(&RSG_genpol); for(i = 0; ; i++) { p = &RSG_multiply[i][0]; for(j = 0; j<2*T; j++) { RSG_shiftregtab[i][j] = p[RSG_genpol.c[j]]; } if(i==MAXELT) break; } } Listing Three /****************************************************** * File: rsmain.c -- main function: repeatedly asks for original string and * string with errors and tries to recover original string from string with * errors using Reed-Solomon decoding * Copyright (c) 1995 by Hugo Lyppens with permission to print in DDJ ******************************************************/ #include "hdr.h" #include #include "rs.h" main(argc, argv) int argc; char *argv[]; { char str[N], str2[N]; int r; RSG_ConstructGaloisField(); RSG_CalcGeneratorPoly(); for(;;) { printf("Enter original string or enter empty string to quit:\n"); memset(str, 0, N); str2[0] = 0; gets(str); if(!str[0]) break; RSG_encode((UBYTE *)str); printf("Enter string with up to %d symbol errors or enter empty string to quit:\n", T); gets(str2); if(!str2[0]) break; strncpy(str, str2, K); r = RSG_decode((UBYTE *)str); if(r < 0) { printf("Decoding error -- too many errors!\n"); } else { printf("Decoding OK, recovered '%s' from '%s' by correcting %d errors!\n", str, str2, r); } } return(0); }