Пример #1
0
bool Reed_solomon_code::chien_search(int length,uint8_t* sigma,int sigma_len,uint8_t* res,int& res_len){
	int jisu=sigma_len-1;
	uint8_t wa=sigma[1];
	uint8_t seki=sigma[jisu];
	if(jisu==1){
		if(shared_galois.log_tbl[wa]>=length)return false;
		res[0]=wa;
		res_len=1;
		return true;
	}
	if(jisu==2){
		res_len=2;
		return chien_search(length,0,wa,seki,res[0],res[1]);
	}

	res_len=jisu;
	int pos_idx=jisu-1;
	for(int i=0,z=255;i<length;i++,z--){
		uint8_t wk=1;
		for(int j=1,wz=z;j<=jisu;j++,wz=(wz+z)%255)
			wk^=shared_galois.mul_exp(sigma[j],wz);
		if(wk==0){
			uint8_t pv=shared_galois.exp_tbl[i];
			wa^=pv;
			seki=shared_galois.div(seki,pv);
			res[pos_idx--]=pv;
			if(pos_idx==1){
				return chien_search(length,i+1,wa,seki,res[0],res[1]);
			}
		}
	}

	return false;
}
// Top level decoder module
void rs_decode (unsigned char n, unsigned char t, unsigned char in_d[nn], 
                unsigned char *k, unsigned char out_d[kk])
{   
   unsigned char temp_k = n - 2*t;
   unsigned char s[2*tt];
   unsigned char c[tt+2];
   unsigned char w[tt+2];
   unsigned char lambda[tt];
   unsigned char omega[tt];
   unsigned char err_no;
   unsigned char err_loc[kk];
   unsigned char alpha_inv[tt];
   unsigned char err[kk];
   unsigned char in_data[kk];
   unsigned char in_d_2[nn];
   
Simple_rs1:   for (int i = 0; i < nn; i++)
       in_d_2[i] = in_d[i];

   *k = temp_k;
   rs_fifo(temp_k, in_d, in_data);
   syndrome(temp_k, t, in_d_2, s);
   berlekamp(t, s, lambda, omega);
   chien_search(kk, tt, lambda, &err_no, err_loc, alpha_inv);
   error_mag(kk, lambda, omega, err_no, err_loc, alpha_inv, err);
   error_correct(temp_k, in_data, err, out_d);
    
}
Пример #3
0
uint8_t* Reed_solomon_code::decode(uint8_t* input){
	uint8_t syn[255];
	if(shared_galois.calc_syndrome(input,n,syn,npar))return input;
	uint8_t sigma[256];
	int sigma_len;
	if(calc_sigma_mbm(syn,sigma,sigma_len)==NULL)return NULL;
	uint8_t pos[256];
	int pos_len;
	if(!chien_search(n,sigma,sigma_len,pos,pos_len))return NULL;
	uint8_t omega[256];
	shared_galois.mul_poly(syn,npar,sigma,sigma_len,omega,sigma_len-1);
	do_forney(input,n,pos,pos_len,sigma,sigma_len,omega,sigma_len-1);
	return input;
}