求RS欧几里德算法解码代码 c或c++的

来源:百度文库 编辑:超级军网 时间:2024/04/25 08:37:43
求RS欧几里德算法解码代码 c或c++的 。水区的大人们帮帮忙吧。求RS欧几里德算法解码代码 c或c++的 。水区的大人们帮帮忙吧。
bm算法也可以。最好有点注释,是不是不该在这里发。
本猪数学不好,不做算法……
猪老大来了啊,本菜技校生什么都做。
欧几里德算法的C语言版


    /*欧几里德算法:辗转求余
  原理: gcd(a,b)=gcd(b,a mod b)
  当b为0时,两数的最大公约数即为a

  getchar()会接受前一个scanf的回车符
*/

#include<stdio.h>

void main()
{
    int temp;
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    printf("the greatest common factor of %d and %d is ",a,b);
    while(b!=0)
    {
        temp=b;
        b=a%b;
        a=temp;
    }
    printf("%d\\n",a);
    getchar();
    getchar();
}
 
 
欧几里德算法的C++/java语言版
[编辑本段]
  欧几里德算法就是根据这个原理来做的,其算法用C++语言描述为:

  void swap(int &; a, int &; b)

  {

  int c = a;

  a = b;

  b = c;

  }

  int gcd(int a,int b)

  {

  if(0 == a )

  {

  return b;

  }

  if( 0 == b)

  {

  return a;

  }

  if(a >; b)

  {

  swap(a,b);

  }

  int c;

  for(c = a % b ; c >; 0 ; c = a % b)

  {

  a = b;

  b = c;

  }

  return b;

  }

  模P乘法逆元

  对于整数a、p,如果存在整数b,满足ab mod p =1,则说,b是a的模p乘法逆元。

  定理:a存在模p的乘法逆元的充要条件是gcd(a,p) = 1

  证明:

  首先证明充分性

  如果gcd(a,p) = 1,根据欧拉定理,aφ(p) ≡ 1 mod p,因此

  显然aφ(p)-1 mod p是a的模p乘法逆元。

  再证明必要性

  假设存在a模p的乘法逆元为b

  ab ≡ 1 mod p

  则ab = kp +1 ,所以1 = ab - kp

  因为gcd(a,p) = d

  所以d | 1

  所以d只能为1
欧几里得算法的概述

  欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。其计算原理依赖于下面的定理:
  定理:gcd(a,b) = gcd(b,a mod b)
  证明:a可以表示成a = kb + r,则r = a mod b
  假设d是a,b的一个公约数,则有
  d|a, d|b,而r = a - kb,因此d|r
  因此d是(b,a mod b)的公约数
  假设d 是(b,a mod b)的公约数,则
  d | b , d |r ,但是a = kb +r
  因此d也是(a,b)的公约数
  因此(a,b)和(b,a mod b)的公约数是一样的,其最大公约数也必然相等,得证




欧几里得算法设计
  辗转相除法是利用以下性质来确定两个正整数 a 和 b 的最大公因子的:
  1. 若 r 是 a ÷ b 的余数, 则
          gcd(a,b) = gcd(b,r)
  2. a 和其倍数之最大公因子为 a。

  另一种写法是:
  1. a ÷ b,令r为所得余数(0≤r<b)
  若 r = 0,算法结束;b 即为答案。
  2. 互换:置 a←b,b←r,并返回第一步。
[:a3:] 对计算机语言没有兴趣的人飘过……
谢谢楼上的那位兄台,不过本菜已经过了那个初级阶段了。本才要的是伽罗华域的多项式修正欧几里德算法的程序。这个整数的太简单鸟。
你这个太专业了点,到专业的论坛上去问好点。
是不是这个:RS码的完整译码程序,采用欧几里德算法
是不是差错控制编码
楼上的对头,汗,别的论坛问了都要分,偶给的分低,没人看。偶倒是有bm算法的程序,没注释看的累
我有那个,不过还是自己留着吧:$ 。
PS:读程序是编程的基本功,阁下好好修炼去吧:victory: 。
不能借书,今天下了个电子版的,总算把欧几里德搞清楚了。福尼只要套公式就可以了。哈哈,明天搞bm。

楼上的不厚道,菜鸟才入门嘛,马上又要写成veriolg。
我是开玩笑的了,别介意哦:lol 。
  编程是比较枯燥,不过钻进去还是很有意思的。把算法搞清楚了,然后用程序实现就好了,专业知识才是最重要的。看别人的程序比自己写还累,不过读多了就熟了。
  那个东西不知道对你有用没 ,RS码的完整译码程序,采用欧几里德算法.采用硬件实现结构,想要的话百度下      RS码的完整译码程序,采用欧几里德算法        就能找到源代码,看看里面有能到的部分不,要是没用就算了。
其实跟同学切磋是个不错的方法。
楼上的是前辈啊,bm的VC程序已经写好了,哈哈。就用ribm吧,硬件上也比欧几里德省资源。:victory:
原帖由 武大郎 于 2008-7-9 06:21 PM 发表
bm算法也可以。最好有点注释,是不是不该在这里发。

恩~应该发到数学版:D
原帖由 天边的风 于 2008-7-10 01:55 AM 发表
我是开玩笑的了,别介意哦:lol 。
  编程是比较枯燥,不过钻进去还是很有意思的。把算法搞清楚了,然后用程序实现就好了,专业知识才是最重要的。看别人的程序比自己写还累,不过读多了就熟了。
  那个东西不知道对 ...

天边还有这门手艺哦:victory:
你们都忽视了猪小弟,这家伙是高手。
原帖由 我立于高山之巅 于 2008-7-10 10:05 发表
你们都忽视了猪小弟,这家伙是高手。

:L
本猪说的素实话,真的不做算法的。VerilogHDL本猪倒是认识,以前经常去www.opencores.org淘代码。
原帖由 猪不戒 于 2008-7-10 10:25 发表

:L
本猪说的素实话,真的不做算法的。VerilogHDL本猪倒是认识,以前经常去www.opencores.org淘代码。



反正我是一窍不通,不过看到你在空军板块发言过,觉得你在计算机方面厉害。
原帖由 我立于高山之巅 于 2008-7-10 10:34 发表



反正我是一窍不通,不过看到你在空军板块发言过,觉得你在计算机方面厉害。

算法实在是很难的东西,本猪太笨,只能做做系统和接口设计这些简单的。

/* rs.c */
/* This program is an encoder/decoder for Reed-Solomon codes. Encoding is in
systematic form, decoding via the Berlekamp iterative algorithm.
In the present form , the constants mm, nn, tt, and kk=nn-2tt must be
specified (the double letters are used simply to avoid clashes with
other n,k,t used in other programs into which this was incorporated!)
Also, the irreducible polynomial used to generate GF(2**mm) must also be
entered -- these can be found in Lin and Costello, and also Clark and Cain.

The representation of the elements of GF(2**m) is either in index form,
where the number is the power of the primitive element alpha, which is
convenient for multiplication (add the powers modulo 2**m-1) or in
polynomial form, where the bits represent the coefficients of the
polynomial representation of the number, which is the most convenient form
for addition. The two forms are swapped between via lookup tables.
This leads to fairly messy looking expressions, but unfortunately, there
is no easy alternative when working with Galois arithmetic.

The code is not written in the most elegant way, but to the best
of my knowledge, (no absolute guarantees!), it works.
However, when including it into a simulation program, you may want to do
some conversion of global variables (used here because I am lazy!) to
local variables where appropriate, and passing parameters (eg array
addresses) to the functions may be a sensible move to reduce the number
of global variables and thus decrease the chance of a bug being introduced.

This program does not handle erasures at present, but should not be hard
to adapt to do this, as it is just an adjustment to the Berlekamp-Massey
algorithm. It also does not attempt to decode past the BCH bound -- see
Blahut "Theory and practice of error control codes" for how to do this.

Simon Rockliff, University of Adelaide 21/9/89

26/6/91 Slight modifications to remove a compiler dependent bug which hadn't
previously surfaced. A few extra comments added for clarity.
Appears to all work fine, ready for posting to net!

Notice
--------
This program may be freely modified and/or given to whoever wants it.
A condition of such distribution is that the author's contribution be
acknowledged by his name being left in the comments heading the program,
however no responsibility is accepted for any financial or other loss which
may result from some unforseen errors or malfunctioning of the program
during use.
Simon Rockliff, 26th June 1991
*/

#i nclude <math.h>
#i nclude <stdio.h>
#i nclude <sys/timeb.h>
#define mm 8 /* RS code over GF(2**4) - change to suit */
#define nn 255 /* nn=2**mm -1 length of codeword */
#define tt 4 /* number of errors that can be corrected */
#define kk 247 /* kk = nn-2*tt */
#define no_p 8 /* no_p = 2*tt */
#define no_t 12 /* no_t = 3*tt */

file://int pp [mm+1] = { 1, 1, 0, 0,1} ; /* specify irreducible polynomial coeffts */
int pp[mm+1] = { 1, 0, 1, 1, 1, 0, 0, 0, 1};
int alpha_to [nn+1], index_of [nn+1], gg [nn-kk+1] ;
int recd [nn], data [kk], bb [nn-kk] ;


void generate_gf()
/* generate GF(2**mm) from the irreducible polynomial p(X) in pp[0]..pp[mm]
lookup tables: index->polynomial form alpha_to[] contains j=alpha**i;
polynomial form -> index form index_of[j=alpha**i] = i
alpha=2 is the primitive element of GF(2**mm)
*/
{
register int i, mask ;

mask = 1 ;
alpha_to[mm] = 0 ;
for (i=0; i<mm; i++)
{ alpha_to = mask ;
index_of[alpha_to] = i ;
if (pp!=0)
alpha_to[mm] ^= mask ;
mask <<= 1 ;
}
index_of[alpha_to[mm]] = mm ;
mask >>= 1 ;
for (i=mm+1; i<nn; i++)
{ if (alpha_to[i-1] >= mask)
alpha_to = alpha_to[mm] ^ ((alpha_to[i-1]^mask)<<1) ;
else alpha_to = alpha_to[i-1]<<1 ;
index_of[alpha_to] = i ;
}
index_of[0] = -1 ;
}


void gen_poly()
/* Obtain the generator polynomial of the tt-error correcting, length
nn=(2**mm -1) Reed Solomon code from the product of (X+alpha**i), i=1..2*tt
*/
{
register int i,j ;

gg[0] = 2 ; /* primitive element alpha = 2 for GF(2**mm) */
gg[1] = 1 ; /* g(x) = (X+alpha) initially */
for (i=2; i<=nn-kk; i++)
{ gg = 1 ;
for (j=i-1; j>0; j--)
if (gg[j] != 0) gg[j] = gg[j-1]^ alpha_to[(index_of[gg[j]]+i)%nn] ;
else gg[j] = gg[j-1] ;
gg[0] = alpha_to[(index_of[gg[0]]+i)%nn] ; /* gg[0] can never be zero */
}
/* convert gg[] to index form for quicker encoding */
for (i=0; i<=nn-kk; i++) gg = index_of[gg] ;
}


void encode_rs()
/* take the string of symbols in data, i=0..(k-1) and encode systematically
to produce 2*tt parity symbols in bb[0]..bb[2*tt-1]
data[] is input and bb[] is output in polynomial form.
Encoding is done by using a feedback shift register with appropriate
connections specified by the elements of gg[], which was generated above.
Codeword is c(X) = data(X)*X**(nn-kk)+ b(X) */
{
register int i,j ;
int feedback ;

for (i=0; i<nn-kk; i++) bb = 0 ;
for (i=kk-1; i>=0; i--)
{ feedback = index_of[data^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 ;
} ;
} ;
} ;

void decode_rs()
/* assume we have received bits grouped into mm-bit symbols in recd,
i=0..(nn-1), and recd is index form (ie as powers of alpha).
We first compute the 2*tt syndromes by substituting alpha**i into rec(X) and
evaluating, storing the syndromes in s, i=1..2tt (leave s[0] zero) .
Then we use the Berlekamp iteration to find the error location polynomial
elp. If the degree of the elp is >tt, we cannot correct all the errors
and hence just put out the information symbols uncorrected. If the degree of
elp is <=tt, we substitute alpha**i , i=1..n into the elp to get the roots,
hence the inverse roots, the error location numbers. If the number of errors
located does not equal the degree of the elp, we have more than tt errors
and cannot correct them. Otherwise, we then solve for the error value at
the error location and correct the error. The procedure is that found in
Lin and Costello. For the cases where the number of errors is known to be too
large to correct, the information symbols as received are output (the
advantage of systematic encoding is that hopefully some of the information
symbols will be okay and that if we are in luck, the errors are in the
parity part of the transmitted codeword). Of course, these insoluble cases
can be returned as error flags to the calling routine if desired. */
{
register int i,j,u,q ;
int elp[nn-kk+2][nn-kk], d[nn-kk+2], l[nn-kk+2], u_lu[nn-kk+2], s[nn-kk+1] ;
int count=0, syn_error=0, root[tt], loc[tt], z[tt+1], err[nn], reg[tt+1] ;

int da[no_p+1][no_t+1];
int st[no_p+1][no_t+1];
int ga[no_p+1];
int kr[no_p+1];
int dg_mul;
int ds_mul;
int omiga;
int sita;
int yi;

/* first form the syndromes */
for (i=1; i<=nn-kk; i++)
{ s = 0 ;
for (j=0; j<nn; j++)
if (recd[j]!=-1)
s ^= alpha_to[(recd[j]+i*j)%nn] ; /* recd[j] in index form */
/* convert syndrome from polynomial form to index form */
if (s!=0) syn_error=1 ; /* set flag if non-zero syndrome => error */
file://s = index_of ;
} ;

file://Ribm algorithm
file://Begin
/* int da[3*tt+1][2*tt+1];
int st[3*tt+1][2*tt+1];
int ga[2*tt+1];
int kr[2*tt+1];
int dg_mul;
int ds_mul;*/

file://Calculate error locator and error evaluator polynomial
for(i=0; i<no_p; i++){
da[0] = s[i+1];
st[0] = s[i+1];
file://da[0] = 1;
file://st[0] = 1;
}

for(i=no_p; i<no_t; i++){
da[0] = 0;
st[0] = 0;
}

da[0][no_t] = 1;
st[0][no_t] = 1;

kr[0] = 0;
ga[0] = 1;

for(i=0; i<no_p; i++){
for(j=0; j<no_t; j++){
if(ga!=0 && da[j+1]!=0)
dg_mul = alpha_to[(index_of[ga] + index_of[da[j+1]])%nn];
else
dg_mul = 0;

if(da[0]!=0 && st[j]!=0)
ds_mul = alpha_to[(index_of[da[0]] + index_of[st[j]])%nn];
else
ds_mul = 0;

da[i+1][j] = dg_mul ^ ds_mul;
}

if(da[0]!=0 && st[no_t]!=0)
da[i+1][no_t] = alpha_to[(index_of[da[0]] + index_of[st[no_t]])%nn];
else
da[i+1][no_t] = 0;

if(da[0]!=0 && kr>=0){
ga[i+1] = da[0];
kr[i+1] = - (kr + 1);
file://kr[i+1] = - (kr - 1);

for(j=0; j<no_t; j++)
st[i+1][j] = da[j+1];

st[i+1][no_t] = 0;
}

else{
ga[i+1] = ga;
kr[i+1] = kr + 1;

for(j=0; j<=no_t; j++)
st[i+1][j] = st[j];
}
}

file://solve the error locator polynomial
for (i=0; i<=tt; i++){
reg = index_of[da[no_p][i+tt]];
if(i<tt)
z = index_of[da[no_p]];
}

count = 0 ;
for (i=1; i<=nn; i++){
q = 0 ;
for (j=0; j<=tt; j++){
if (reg[j]!=-1){
reg[j] = (reg[j]+j)%nn ;
q ^= alpha_to[reg[j]] ;
}
}

if (!q){
root[count] = i;
loc[count] = nn-i ;
count++ ;
}
}

/* file://For reference
for(i=1; i<=nn; i++){
omiga = 0;
for(j=0; j<tt; j++){
if(z[j]!=-1)
omiga ^= alpha_to[(z[j]+i*j)%nn];
}

sita = 0;
for(j=0; j<=tt; j++){
if((j%2)!=0 && reg[j]!=-1)
sita ^= alpha_to[(reg[j]+i*j)%nn];
}
}
file://End of reference*/


file://calculate the error value and correct
for (i=0; i<nn; i++){
err = 0 ;
if (recd!=-1) // convert recd[] to polynomial form
recd = alpha_to[recd] ;
else
recd = 0 ;
}

for (i=0; i<count; i++){
omiga = 0;
for(j=0; j<tt; j++){
if(z[j]!=-1 && root!=-1)
omiga ^= alpha_to[(z[j]+root*j)%nn];
}

sita = 0;
for(j=0; j<=tt; j++){
if((j%2)!=0 && reg[j]!=-1 && root!=-1)
sita ^= alpha_to[(reg[j]+root*j)%nn];
}

file://sita = alpha_to[nn-index_of[sita]];
file://yi = alpha_to[root*(no_p+1)%nn];

/*yi = (root*(no_p-1))%nn;
if(omiga!=0)
yi = (yi + index_of[omiga])%nn;
if(sita!=0)
yi = (yi + nn - index_of[sita])%nn;*/
yi = (root*(no_p+1) + index_of[omiga] + nn - index_of[sita])%nn;
err[loc] = alpha_to[yi];

recd[loc] ^= err[loc];
}

/*yi = alpha_to[nn-index_of[109]];
yi = alpha_to[nn-index_of[176]];
yi = alpha_to[nn-index_of[254]];*/

yi = alpha_to[(index_of[12]+index_of[5])%nn];
yi = alpha_to[(index_of[125]+index_of[156])%nn];
yi = alpha_to[(index_of[184]+index_of[240])%nn];

yi = alpha_to[(index_of[60]+index_of[236])%nn];
yi = alpha_to[(index_of[201]+index_of[135])%nn];
yi = alpha_to[(index_of[178]+index_of[126])%nn];

for(i=0; i<nn; i++)
recd = index_of[recd];

syn_error = 0;
file://End

if (syn_error) /* if errors, try and correct */
{
/* compute the error location polynomial via the Berlekamp iterative algorithm,
following the terminology of Lin and Costello : d is the 'mu'th
discrepancy, where u='mu'+1 and 'mu' (the Greek letter!) is the step number
ranging from -1 to 2*tt (see L&C), l is the
degree of the elp at that step, and u_l is the difference between the
step number and the degree of the elp.
*/
/* initialise table entries */
d[0] = 0 ; /* index form */
d[1] = s[1] ; /* index form */
elp[0][0] = 0 ; /* index form */
elp[1][0] = 1 ; /* polynomial form */
for (i=1; i<nn-kk; i++)
{ elp[0] = -1 ; /* index form */
elp[1] = 0 ; /* polynomial form */
}
l[0] = 0 ;
l[1] = 0 ;
u_lu[0] = -1 ;
u_lu[1] = 0 ;
u = 0 ;

do
{
u++ ;
if (d==-1)
{ l[u+1] = l ;
for (i=0; i<=l; i++)
{ elp[u+1] = elp ;
elp = index_of[elp] ;
}
}
else
/* search for words with greatest u_lu[q] for which d[q]!=0 */
{ q = u-1 ;
while ((d[q]==-1) && (q>0)) q-- ;
/* have found first non-zero d[q] */
if (q>0)
{ j=q ;
do
{ j-- ;
if ((d[j]!=-1) && (u_lu[q]<u_lu[j]))
q = j ;
}while (j>0) ;
} ;

/* have now found q such that d!=0 and u_lu[q] is maximum */
/* store degree of new elp polynomial */
if (l>l[q]+u-q) l[u+1] = l ;
else l[u+1] = l[q]+u-q ;

/* form new elp(x) */
for (i=0; i<nn-kk; i++) elp[u+1] = 0 ;
for (i=0; i<=l[q]; i++)
if (elp[q]!=-1)
elp[u+1][i+u-q] = alpha_to[(d+nn-d[q]+elp[q])%nn] ;
for (i=0; i<=l; i++)
{ elp[u+1] ^= elp ;
elp = index_of[elp] ; /*convert old elp value to index*/
}
}
u_lu[u+1] = u-l[u+1] ;

/* form (u+1)th discrepancy */
if (u<nn-kk) /* no discrepancy computed on last iteration */
{
if (s[u+1]!=-1)
d[u+1] = alpha_to[s[u+1]] ;
else
d[u+1] = 0 ;
for (i=1; i<=l[u+1]; i++)
if ((s[u+1-i]!=-1) && (elp[u+1]!=0))
d[u+1] ^= alpha_to[(s[u+1-i]+index_of[elp[u+1]])%nn] ;
d[u+1] = index_of[d[u+1]] ; /* put d[u+1] into index form */
}
} while ((u<nn-kk) && (l[u+1]<=tt)) ;

u++ ;
if (l<=tt) /* can correct error */
{
/* put elp into index form */
for (i=0; i<=l; i++) elp = index_of[elp] ;

/* find roots of the error location polynomial */
for (i=1; i<=l; i++)
reg = elp ;
count = 0 ;
for (i=1; i<=nn; i++)
{ q = 1 ;
for (j=1; j<=l; j++)
if (reg[j]!=-1)
{ reg[j] = (reg[j]+j)%nn ;
q ^= alpha_to[reg[j]] ;
} ;
if (!q) /* store root and error location number indices */
{ root[count] = i;
loc[count] = nn-i ;
count++ ;
};
} ;
if (count==l) /* no. roots = degree of elp hence <= tt errors */
{
/* form polynomial z(x) */
for (i=1; i<=l; i++) /* Z[0] = 1 always - do not need */
{ if ((s!=-1) && (elp!=-1))
z = alpha_to ^ alpha_to[elp] ;
else if ((s!=-1) && (elp==-1))
z = alpha_to ;
else if ((s==-1) && (elp!=-1))
z = alpha_to[elp] ;
else
z = 0 ;
for (j=1; j<i; j++)
if ((s[j]!=-1) && (elp[i-j]!=-1))
z ^= alpha_to[(elp[i-j] + s[j])%nn] ;
z = index_of[z] ; /* put into index form */
} ;

/* evaluate errors at locations given by error location numbers loc */
for (i=0; i<nn; i++)
{ err = 0 ;
if (recd!=-1) /* convert recd[] to polynomial form */
recd = alpha_to[recd] ;
else recd = 0 ;
}
for (i=0; i<l; i++) /* compute numerator of error term first */
{ err[loc] = 1; /* accounts for z[0] */
for (j=1; j<=l; j++)
if (z[j]!=-1)
err[loc] ^= alpha_to[(z[j]+j*root)%nn] ;
if (err[loc]!=0)
{ err[loc] = index_of[err[loc]] ;
q = 0 ; /* form denominator of error term */
for (j=0; j<l; j++)
if (j!=i)
q += index_of[1^alpha_to[(loc[j]+root)%nn]] ;
q = q % nn ;
err[loc] = alpha_to[(err[loc]-q+nn)%nn] ;
recd[loc] ^= err[loc] ; /*recd must be in polynomial form */
}
}
}
else /* no. roots != degree of elp => >tt errors and cannot solve */
for (i=0; i<nn; i++) /* could return error flag if desired */
if (recd!=-1) /* convert recd[] to polynomial form */
recd = alpha_to[recd] ;
else recd = 0 ; /* just output received codeword as is */
}
else /* elp has degree has degree >tt hence cannot solve */
for (i=0; i<nn; i++) /* could return error flag if desired */
if (recd!=-1) /* convert recd[] to polynomial form */
recd = alpha_to[recd] ;
else recd = 0 ; /* just output received codeword as is */
}
else /* no non-zero syndromes => no errors: output received codeword */
for (i=0; i<nn; i++)
if (recd!=-1) /* convert recd[] to polynomial form */
recd = alpha_to[recd] ;
else recd = 0 ;
}

main()
{
register int i, k;
struct _timeb t1, t2;
int err_dec;

generate_gf() ;
gen_poly() ;

file://for (i=0; i<kk; i++) data = rand()%256 ;
for(i=0; i<kk; i++){
data = kk+2-i;
if(data>=256)
data = data - 256;
}

_ftime(&t1);
for (i = 0; i < 10000; i ++)
encode_rs() ;
_ftime(&t2);

i = (t2.millitm-t1.millitm)+(t2.time-t1.time)*1000;

for (i=0; i<nn-kk; i++) recd = bb ;
for (i=0; i<kk; i++) recd[i+nn-kk] = data ;

/*for (k = 0; k < tt; k ++)
recd[rand()%nn] = rand()%256;*/

/*for(k=0; k<nn; k++)
recd[k] = 255-k+2;

recd[1] = 0;
recd[0] = 1;*/

recd[252] = 11;
recd[228] = 56;
recd[212] = 232;
file://recd[193] = 197;
file://recd[161] = 25;
file://recd[92] = 133;

_ftime(&t1);
file://for (i = 0; i < 10000; i ++)
for (i = 0; i < 1; i ++)
{
for (k=0; k<nn; k++)
recd[k] = index_of[recd[k]] ; /* put recd into index form */
decode_rs() ; /* recd[] is returned in polynomial form */
}
_ftime(&t2);

i = (t2.millitm-t1.millitm)+(t2.time-t1.time)*1000;

err_dec = 1;
for (i = 0; i <kk; i++){
if (recd[i+nn-kk] != data){
err_dec = 0;
break;
}
}
}
貌似可以参考这个吧:
RS系列编译码器的设计与FPGA实现
http://www.studa.net/yingyong/080505/09403474.html