所罗门校验算法C#版

所罗门算法可以提供数据校验和纠错功能,详细的算法介绍大家可以查看关于此算法的专题介绍!以下是我从C转到C#的所罗门算法,希望能为在C#下进行通信的朋友给以帮助!
None.gif public   class  SOLOMN
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
"数组定义"#region "数组定义"
InBlock.gif
InBlock.gif        
private byte[] ceolongitude = new byte[]
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
174,173,172,171,169,168,167,165,164,162,
InBlock.gif                
161,159,157,156,154,152,150,148,146,144,
InBlock.gif                
142,140,138,136,133,131,129,127,124,122,
InBlock.gif                
120,117,114,112,109
ExpandedSubBlockEnd.gif            }
;
InBlock.gif        
private byte[] exp_table = new byte[]
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
1,   2,   4,   8,  16,  32,  64128,  29,  58116232205135,  19,  38,
InBlock.gif                
76152,  45,  90180117234201143,   3,   6,  12,  24,  48,  96192,
InBlock.gif                
157,  39,  78156,  37,  74148,  53106212181119238193159,  35,
InBlock.gif                
70140,   5,  10,  20,  40,  80160,  93186105210185111222161,
InBlock.gif                
95190,  97194153,  47,  94188101202137,  15,  30,  60120240,
InBlock.gif                
253231211187107214177127254225223163,  91182113226,
InBlock.gif                
217175,  67134,  17,  34,  68136,  13,  26,  52104208189103206,
InBlock.gif                
129,  31,  62124248237199147,  59118236197151,  51102204,
InBlock.gif                
133,  23,  46,  92184109218169,  79158,  33,  66132,  21,  42,  84,
InBlock.gif                
168,  77154,  41,  82164,  85170,  73146,  57114228213183115,
InBlock.gif                
230209191,  99198145,  63126252229215179123246241255,
InBlock.gif                
227219171,  75150,  49,  98196149,  55110220165,  87174,  65,
InBlock.gif                
130,  25,  50100200141,   7,  14,  28,  56112224221167,  83166,
InBlock.gif                
81162,  89178121242249239195155,  43,  86172,  69138,   9,
InBlock.gif                
18,  36,  72144,  61122244245247243251235203139,  11,  22,
InBlock.gif                
44,  88176125250233207131,  27,  54108216173,  71142,   1,
InBlock.gif                
2,   4,   8,  16,  32,  64128,  29,  58116232205135,  19,  38,  76,
InBlock.gif                
152,  45,  90180117234201143,   3,   6,  12,  24,  48,  96192157,
InBlock.gif                
39,  78156,  37,  74148,  53106212181119238193159,  35,  70,
InBlock.gif                
140,   5,  10,  20,  40,  80160,  93186105210185111222161,  95,
InBlock.gif                
190,  97194153,  47,  94188101202137,  15,  30,  60120240253,
InBlock.gif                
231211187107214177127254225223163,  91182113226217,
InBlock.gif                
175,  67134,  17,  34,  68136,  13,  26,  52104208189103206129,
InBlock.gif                
31,  62124248237199147,  59118236197151,  51102204133,
InBlock.gif                
23,  46,  92184109218169,  79158,  33,  66132,  21,  42,  84168,
InBlock.gif                
77154,  41,  82164,  85170,  73146,  57114228213183115230,
InBlock.gif                
209191,  99198145,  63126252229215179123246241255227,
InBlock.gif                
219171,  75150,  49,  98196149,  55110220165,  87174,  65130,
InBlock.gif                
25,  50100200141,   7,  14,  28,  56112224221167,  83166,  81,
InBlock.gif                
162,  89178121242249239195155,  43,  86172,  69138,   9,  18,
InBlock.gif                
36,  72144,  61122244245247243251235203139,  11,  22,  44,
InBlock.gif                
88176125250233207131,  27,  54108216173,  71142,   1,   0
ExpandedSubBlockEnd.gif            }
;
InBlock.gif        
private byte[] log_table = new byte[]
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
0,   0,   1,  25,   2,  50,  26198,   3223,  51238,  27104199,  75,
InBlock.gif                
4100224,  14,  52141239129,  28193105248200,   8,  76113,
InBlock.gif                
5138101,  47225,  36,  15,  33,  53147142218240,  18130,  69,
InBlock.gif                
29181194125106,  39249185201154,   9120,  77228114166,
InBlock.gif                
6191139,  98102221,  48253226152,  37179,  16145,  34136,
InBlock.gif                
54208148206143150219189241210,  19,  92131,  56,  70,  64,
InBlock.gif                
30,  66182163195,  72126110107,  58,  40,  84250133186,  61,
InBlock.gif                
202,  94155159,  10,  21121,  43,  78212229172115243167,  87,
InBlock.gif                
7112192247140128,  99,  13103,  74222237,  49197254,  24,
InBlock.gif                
227165153119,  38184180124,  17,  68146217,  35,  32137,  46,
InBlock.gif                
55,  63209,  91149188207205144135151178220252190,  97,
InBlock.gif                
242,  86211171,  20,  42,  93158132,  60,  57,  83,  71109,  65162,
InBlock.gif                
31,  45,  67216183123164118196,  23,  73236127,  12111246,
InBlock.gif                
108161,  59,  82,  41157,  85170251,  96134177187204,  62,  90,
InBlock.gif                
203,  89,  95176156169160,  81,  11245,  22235122117,  44215,
InBlock.gif                
79174213233230231173232116214244234168,  80,  88175
ExpandedSubBlockEnd.gif            }
;
InBlock.gif        
private byte[] gen_poly = new byte[]
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
116231216,  30,   1,   0,   0,   0,   0,   
InBlock.gif                
0,   0,   0,   0,   0,   0,   0
ExpandedSubBlockEnd.gif            }
;
InBlock.gif        
private byte[] donotuse = new byte[]
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{0xff};
InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif        
private const int DECODED_DATA_SIZE = 28
InBlock.gif        
private const int ENCODED_DATA_SIZE = 32;
InBlock.gif        
private const int NUM_PARITY_BYTES  = (ENCODED_DATA_SIZE - DECODED_DATA_SIZE); 
InBlock.gif        
private const int SYNDROME_LENGTH   = NUM_PARITY_BYTES * 2;
InBlock.gif        
private const int POLY_SIZE         = NUM_PARITY_BYTES * 2
InBlock.gif        
private const int DOUBLE_POLY_SIZE  = POLY_SIZE * 2
InBlock.gif        
//unsigned char REEDSOLOMON[32];
ExpandedSubBlockStart.gifContractedSubBlock.gif
        /**//// <summary>
InBlock.gif        
/// 入口字节数组
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public byte[] COMMONTEMP = new byte[1063];
InBlock.gif        
private static byte[] rstemp = new byte[52];
InBlock.gif
InBlock.gif        
private byte fast_mult(byte a,byte b)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if((a==0)||(b==0))
InBlock.gif                
return 0;
InBlock.gif            
else return exp_table[log_table[a] + log_table[b]];
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private byte fast_inv(byte elt)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return exp_table[255 - log_table[elt]];
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="msg_length"></param>

InBlock.gif        public void encode_data(int msg_length)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int i;
InBlock.gif            
byte c, temp;
InBlock.gif            
byte[] msg = new byte[28];
InBlock.gif            
byte[] codeword = new byte[32];
InBlock.gif            
byte[] parity = new byte[4];
InBlock.gif            
for(i=0;i<msg_length;i++)msg[i]=COMMONTEMP[i];
InBlock.gif            
if (msg_length > 28)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return//JUST CANT DO IT SO RETURN
ExpandedSubBlockEnd.gif
            }

InBlock.gif            
for(i=0;i<msg_length;i++)codeword[i]=msg[i];
InBlock.gif            
for(i=0;i<4;i++)codeword[msg_length+i]=0;
InBlock.gif            
for(i=0;i<4;i++)parity[i]=0;
InBlock.gif            
// Calculate the parity bytes
InBlock.gif
            for (i = 0; i < msg_length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ( (codeword[i] ^ parity[3]) != 0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    c 
= log_table[codeword[i] ^ parity[3]];
InBlock.gif                    temp 
= exp_table[log_table[0x1E+ c];
InBlock.gif                    parity[
3= (byte)(parity[2]^temp);
InBlock.gif
InBlock.gif                    temp 
= exp_table[log_table[0xD8+ c];
InBlock.gif                    parity[
2= (byte)(parity[1]^temp);                            
InBlock.gif              
InBlock.gif                    temp 
= exp_table[log_table[0xE7+ c];
InBlock.gif                    parity[
1= (byte)(parity[0]^temp);  
InBlock.gif            
InBlock.gif                    parity[
0= exp_table[log_table[0x74+ c];
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    parity[
3= (byte)(parity[2]^0);
InBlock.gif                    parity[
2= (byte)(parity[1]^0);
InBlock.gif                    parity[
1= (byte)(parity[0]^0);
InBlock.gif                    parity[
0= 0;
ExpandedSubBlockEnd.gif                }

InBlock.gif        
ExpandedSubBlockEnd.gif            }

InBlock.gif            
// REORDER THE PARITY BYTES FROM  0, 1, 2, 3 --> 3, 2, 1, 0
InBlock.gif
            c = parity[0];
InBlock.gif            parity[
0= parity[3];
InBlock.gif            parity[
3= c;
InBlock.gif            c 
= parity[1];
InBlock.gif            parity[
1= parity[2];
InBlock.gif            parity[
2= c;
InBlock.gif            
for(i=0;i<4;i++)//codeword[msg_length+i]=parity[i];
InBlock.gif                
//for(i=0;i<32;i++)REEDSOLOMON[i]=codeword[i];
InBlock.gif
                COMMONTEMP[msg_length+i] = parity[i];
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="codeword_len"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public int decode_data(byte codeword_len)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int i, j, rc = 0;
InBlock.gif            
byte sum,temp,temp1;
InBlock.gif            
byte[] codeword = new byte[32];
InBlock.gif            
byte[] syndrome = new byte[8];
InBlock.gif            
for(i=0;i<codeword_len + 4;i++)codeword[i]=COMMONTEMP[i];
InBlock.gif   
InBlock.gif            
for(i=0;i<8;i++)syndrome[i]=0;
InBlock.gif            
for (i = 0; i < 4; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                sum 
= 0;
InBlock.gif                temp1 
= exp_table[i+1];
InBlock.gif                
for (j = 0; j < (codeword_len+4); j++
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if ( sum != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        temp 
= exp_table[log_table[temp1] + log_table[sum]];
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        temp 
= 0;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    sum 
= (byte)(codeword[j] ^ temp);
ExpandedSubBlockEnd.gif                }

InBlock.gif      
InBlock.gif                rc 
+= (syndrome[i] = sum);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
for(i=0;i<8;i++)rstemp[i]=syndrome[i];
InBlock.gif            
return rc;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="codeword_len"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public bool Do_Decode_Data(byte codeword_len)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if(decode_data(codeword_len) == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(decode_data(codeword_len) > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (correct_errors(codeword_len) == 0);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return true;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private byte compute_discrepancy(int L, int n)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int i;
InBlock.gif            
byte[] syndrome = new byte[8];
InBlock.gif            
byte[] lambda = new byte[8];
InBlock.gif            
byte sum=0;
InBlock.gif            
for (i = 0; i < 8; i++)lambda[i]=rstemp[28+i];
InBlock.gif            
for (i = 0; i < 8; i++)syndrome[i]=rstemp[i];    
InBlock.gif            
for (i = 0; i <= L; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                sum 
^= fast_mult(lambda[i], syndrome[n-i]);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return sum;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void mult_polys()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int i, j, k;
InBlock.gif            
byte[] dst = new byte[16];
InBlock.gif            
byte[] p1 = new byte[8];
InBlock.gif            
byte[] p2 = new byte[8];
InBlock.gif            
byte[] tmp1 = new byte[16];
InBlock.gif            
for(i=0;i<16;i++)dst[i]=0;
InBlock.gif            
for(i=0;i<8;i++)p1[i]=rstemp[8+i];
InBlock.gif            
for(i=0;i<8;i++)p2[i]=rstemp[i];
InBlock.gif            
for (i = 0; i < 8; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for(k=0;k<8;k++)tmp1[8+k]=0;
InBlock.gif                
//       scale tmp1 by p1[i] 
InBlock.gif
                for(j = 0; j < 8; j++
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tmp1[j] 
= fast_mult(p2[j], p1[i]);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
//       and mult (shift) tmp1 right by i 
InBlock.gif
                for (j = 15; j >= i; j--
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tmp1[j] 
= tmp1[j-i];
ExpandedSubBlockEnd.gif                }

InBlock.gif                
for(k=0;k<i;k++)tmp1[k]=0;
InBlock.gif
InBlock.gif                
//       add into partial product 
InBlock.gif
                for (j = 0; j < 16; j++
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    dst[j] 
^= tmp1[j];
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
for(i=0;i<16;i++)rstemp[36+i]=dst[i];
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void compute_modified_omega()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
byte[] product = new byte[16];
InBlock.gif            
byte[] omega = new byte[8];
InBlock.gif            
int i;
InBlock.gif            mult_polys();
InBlock.gif            
for(i=0;i<16;i++)product[i]=rstemp[36+i];
InBlock.gif            
for(i=0;i<8;i++)omega[i]=0;
InBlock.gif            
for(i=0;i<4;i++)omega[i]=product[i];
InBlock.gif            
for(i=0;i<8;i++)rstemp[16+i]=omega[i];
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
private void Modified_Berlekamp_Massey()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
int i, n, L = 0, L2, k = -1;
InBlock.gif            
byte j;
InBlock.gif            
byte[] lambda = new byte[8];
InBlock.gif            
byte d;
InBlock.gif            
byte[] psi = new byte[8];
InBlock.gif            
byte[] psi2 = new byte[8];
InBlock.gif            
byte[] D = new byte[8];
InBlock.gif            
for(i=0;i<8;i++)D[i]=0;
InBlock.gif   
InBlock.gif            D[
0= 1;
InBlock.gif   
InBlock.gif            
for (i = 7; i > 0; i--)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                D[i] 
= D[i-1];
ExpandedSubBlockEnd.gif            }

InBlock.gif            D[
0= 0;
InBlock.gif   
InBlock.gif            
for(i=0;i<8;i++)psi[i]=0;
InBlock.gif   
InBlock.gif            psi[
0= 1;
InBlock.gif
InBlock.gif            
for (n = 0; n < 4; n++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
for(j=0;j<8;j++)rstemp[28+j]=psi[j];
InBlock.gif          
InBlock.gif                d 
= compute_discrepancy(L, n);
InBlock.gif
InBlock.gif                
if (d != 0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{        
InBlock.gif                    
//          psi2 = psi - d*D 
InBlock.gif
                    for (i = 0; i < 8; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        psi2[i] 
= (byte)(psi[i] ^ fast_mult(d, D[i]));
ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif                    
if (L < (n-k)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        L2 
= n-k;
InBlock.gif                        k 
= n;
InBlock.gif                        
for (i = 0; i < 4; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            D[i] 
= fast_mult(psi[i], fast_inv(d));
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        L 
= L2;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
for (i = 0; i < 8; i++)psi[i]=psi2[i];
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
for (i = 7; i > 0; i--)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    D[i] 
= D[i-1];
ExpandedSubBlockEnd.gif                }

InBlock.gif                D[
0= 0;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
for (i = 0; i < 8; i++)lambda[i]=psi[i];
InBlock.gif            
for(i=0;i<8;i++)rstemp[8+i]=lambda[i];
InBlock.gif            compute_modified_omega();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
// given Psi (called Lambda in Modified_Berlekamp_Massey) and synBytes,
InBlock.gif        
// compute the combined erasure/error evaluator polynomial as Psi*S mod z^4
InBlock.gif

InBlock.gif
InBlock.gif        
private int Find_Roots()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int sum, i, j, errors = 0;    
InBlock.gif            
byte[] lambda = new byte[8];
InBlock.gif            
byte[] error_locations = new byte[4];
InBlock.gif            
for (i = 0; i < 8; i++)lambda[i]=rstemp[8+i];
InBlock.gif            
for (i = 1; i < 255; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                sum 
= 0;
InBlock.gif
InBlock.gif                
for (j = 0; j < 5; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    sum 
^= fast_mult(exp_table[(j * i) % 255], lambda[j]);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
if (sum == 0
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    error_locations[errors] 
= (byte)(255-i);
InBlock.gif                    errors
++
InBlock.gif
InBlock.gif                    
// Don't bother finding more errors then we can correct
InBlock.gif
                    if (errors > 4)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
for (i = 0; i < 4; i++)rstemp[24+i]=error_locations[i];
InBlock.gif            
return errors;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int correct_errors(byte codeword_len)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int r, i, j, err, num_errors;
InBlock.gif            
byte num, denom;
InBlock.gif            
byte[] codeword = new byte[32];
InBlock.gif            
byte[] syndrome = new byte[8];
InBlock.gif            
byte[] error_locations = new byte[4];
InBlock.gif            
byte[] lambda = new byte[8];
InBlock.gif            
byte[] omega = new byte[8];
InBlock.gif            
for(i=0;i<32;i++)codeword[i]=COMMONTEMP[i];
InBlock.gif            
for(i=0;i<8;i++)syndrome[i]=rstemp[i];
InBlock.gif   
InBlock.gif            Modified_Berlekamp_Massey();
InBlock.gif            
for(i=0;i<8;i++)lambda[i]=rstemp[8+i];
InBlock.gif            
for(i=0;i<8;i++)omega[i]=rstemp[16+i];
InBlock.gif            num_errors 
= Find_Roots();
InBlock.gif            
for(i=0;i<4;i++)error_locations[i]=rstemp[24+i];
InBlock.gif            
if (num_errors > 4return 1;
InBlock.gif
InBlock.gif            
for (r = 0; r < num_errors; r++
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//       first check for illegal error locs 
InBlock.gif
                if (error_locations[r] >= (codeword_len+4))  // Modified from DECODED_DATA_SIZE
ExpandedSubBlockStart.gifContractedSubBlock.gif
                dot.gif{
InBlock.gif                    
for(i=0;i<32;i++)COMMONTEMP[i]=codeword[i];
InBlock.gif                    
return 1;
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                i 
= error_locations[r];
InBlock.gif
InBlock.gif                
//       evaluate Omega at alpha^(-i) 
InBlock.gif
                num = 0;
InBlock.gif                
for (j = 0; j < 8; j++
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num 
^= fast_mult(omega[j], exp_table[((255 - i) * j) % 255]);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
//       evaluate Lambda' (derivative) at alpha^(-i) ; all odd powers disappear 
InBlock.gif
                denom = 0;
InBlock.gif                
for (j = 1; j < 8; j += 2
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    denom 
^= fast_mult(lambda[j], exp_table[((255 - i ) * (j - 1)) & 0xFF]);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                err 
= fast_mult(num, fast_inv(denom));
InBlock.gif                codeword[codeword_len 
- i +3= (byte)(codeword[codeword_len - i +3^ err);
InBlock.gif                
//codeword[codeword_len - i +3] ^= err;
ExpandedSubBlockEnd.gif
            }

InBlock.gif            
for(i=0;i<32;i++)COMMONTEMP[i]=codeword[i];    
InBlock.gif            
return 0;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif    }

转载于:https://www.cnblogs.com/canny/archive/2006/01/06/312130.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值