MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / Decode

Method Decode

Libraries/unrar/rs.cpp:93–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92
93bool RSCoder::Decode(byte *Data,int DataSize,int *EraLoc,int EraSize)
94{
95 int SynData[MAXPOL]; // Syndrome data.
96
97 bool AllZeroes=true;
98 for (int I=0;I<ParSize;I++)
99 {
100 int Sum=0;
101 for (int J=0;J<DataSize;J++)
102 Sum=Data[J]^gfMult(gfExp[I+1],Sum);
103 if ((SynData[I]=Sum)!=0)
104 AllZeroes=false;
105 }
106
107 // If all syndrome numbers are zero, message does not have errors.
108 if (AllZeroes)
109 return(true);
110
111 if (!FirstBlockDone) // Do things which we need to do once for all data.
112 {
113 FirstBlockDone=true;
114
115 // Calculate the error locator polynomial.
116 Clean(ELPol,ParSize+1);
117 ELPol[0]=1;
118
119 for (int EraPos=0;EraPos<EraSize;EraPos++)
120 for (int I=ParSize,M=gfExp[DataSize-EraLoc[EraPos]-1];I>0;I--)
121 ELPol[I]^=gfMult(M,ELPol[I-1]);
122
123 ErrCount=0;
124
125 // Find roots of error locator polynomial.
126 for (int Root=MAXPAR-DataSize;Root<MAXPAR+1;Root++)
127 {
128 int Sum=0;
129 for (int B=0;B<ParSize+1;B++)
130 Sum^=gfMult(gfExp[(B*Root)%MAXPAR],ELPol[B]);
131 if (Sum==0) // Root found.
132 {
133 ErrorLocs[ErrCount]=MAXPAR-Root; // Location of error.
134
135 // Calculate the denominator for every error location.
136 Dnm[ErrCount]=0;
137 for (int I=1;I<ParSize+1;I+=2)
138 Dnm[ErrCount]^= gfMult(ELPol[I],gfExp[Root*(I-1)%MAXPAR]);
139
140 ErrCount++;
141 }
142 }
143 }
144
145 int EEPol[MAXPOL]; // Error Evaluator Polynomial.
146 pnMult(ELPol,SynData,EEPol);
147 // If errors are present and their number is correctable.
148 if ((ErrCount<=ParSize) && ErrCount>0)
149 for (int I=0;I<ErrCount;I++)
150 {

Callers 3

DecodeBufMethod · 0.45
ReadHeader15Method · 0.45
DecodeCharMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected