// Reed-Solomon encoder and decoder in C++ using galois class libraries // Implements a (255,223) RS encoder and errors-and-erasures decoder // February 17, 1999 // Copyright 1999 Phil Karn // May be used under the terms of the GNU Public License (GPL) // User functions: // void rs_init(void) - always call this first! // void encode_rs(dtype data[KK], dtype bb[NN-KK]); // data = message data in, bb = parity symbols out // int eras_dec_rs(dtype data[NN], int eras_pos[NN-KK], int no_eras); // data = codeword in // eras_pos = list of erasure locations, if any; may be NULL if no_eras == 0 // no_eras = number of entries in eras_pos[] // returns number of corrected errors, or -1 if failure (too many errors) // Still to do: support for nonconsecutive generator roots, e.g., like // those used in the CCSDS standard #include #include "galois.h" #include "rs.h" int KK(239); // Number of data symbols in block const int B0(1); // First consecutive root of generator polynomial // RS generator polynomial polynomial g; // form Reed-Solomon generator polynomial g // Must call this before calling encoder or decoder void rs_init(void) { int i; g = 1; for(i=B0;i=0; j-= 2){ den += lfsr[j+1] * (lfsr_roots[i]^j); } if(den == 0) return -1; received[lfsr_roots[i].inv().index()] -= num/den; // apply correction } // JR: overwrite with corrected data for(i=0;i