void CBC_ReedSolomonDecoder::Decode(CFX_Int32Array* received, int32_t twoS, int32_t& e) { CBC_ReedSolomonGF256Poly poly; poly.Init(m_field, received, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CFX_Int32Array syndromeCoefficients; syndromeCoefficients.SetSize(twoS); FX_BOOL dataMatrix = FALSE; FX_BOOL noError = TRUE; for (int32_t i = 0; i < twoS; i++) { int32_t eval = poly.EvaluateAt(m_field->Exp(dataMatrix ? i + 1 : i)); syndromeCoefficients[twoS - 1 - i] = eval; if (eval != 0) { noError = FALSE; } } if (noError) { return; } CBC_ReedSolomonGF256Poly syndrome; syndrome.Init(m_field, &syndromeCoefficients, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_ReedSolomonGF256Poly* rsg = m_field->BuildMonomial(twoS, 1, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg); CFX_PtrArray* pa = RunEuclideanAlgorithm(temp.get(), &syndrome, twoS, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_AutoPtr<CFX_PtrArray> sigmaOmega(pa); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> sigma( (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[0]); CBC_AutoPtr<CBC_ReedSolomonGF256Poly> omega( (CBC_ReedSolomonGF256Poly*)(*sigmaOmega)[1]); CFX_Int32Array* ia1 = FindErrorLocations(sigma.get(), e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_AutoPtr<CFX_Int32Array> errorLocations(ia1); CFX_Int32Array* ia2 = FindErrorMagnitudes(omega.get(), errorLocations.get(), dataMatrix, e); BC_EXCEPTION_CHECK_ReturnVoid(e); CBC_AutoPtr<CFX_Int32Array> errorMagnitudes(ia2); for (int32_t k = 0; k < errorLocations->GetSize(); k++) { int32_t position = received->GetSize() - 1 - m_field->Log((*errorLocations)[k], e); BC_EXCEPTION_CHECK_ReturnVoid(e); if (position < 0) { e = BCExceptionBadErrorLocation; BC_EXCEPTION_CHECK_ReturnVoid(e); } (*received)[position] = CBC_ReedSolomonGF256::AddOrSubtract( (*received)[position], (*errorMagnitudes)[k]); } }
void ReedSolomonDecoder::decode(ArrayRef<int> received, int twoS) { Ref<GF256Poly> poly(new GF256Poly(field, received)); #ifdef DEBUG cout << "decoding with poly " << *poly << "\n"; #endif ArrayRef<int> syndromeCoefficients(new Array<int> (twoS)); #ifdef DEBUG cout << "syndromeCoefficients array = " << syndromeCoefficients.array_ << "\n"; #endif bool dataMatrix = (&field == &GF256::DATA_MATRIX_FIELD); bool noError = true; for (int i = 0; i < twoS; i++) { int eval = poly->evaluateAt(field.exp(dataMatrix ? i + 1 : i)); syndromeCoefficients[syndromeCoefficients->size() - 1 - i] = eval; if (eval != 0) { noError = false; } } if (noError) { return; } Ref<GF256Poly> syndrome(new GF256Poly(field, syndromeCoefficients)); Ref<GF256Poly> monomial(field.buildMonomial(twoS, 1)); vector<Ref<GF256Poly> > sigmaOmega(runEuclideanAlgorithm(monomial, syndrome, twoS)); ArrayRef<int> errorLocations = findErrorLocations(sigmaOmega[0]); ArrayRef<int> errorMagitudes = findErrorMagnitudes(sigmaOmega[1], errorLocations, dataMatrix); for (unsigned i = 0; i < errorLocations->size(); i++) { int position = received->size() - 1 - field.log(errorLocations[i]); //TODO: check why the position would be invalid if (position < 0 || (size_t)position >= received.size()) throw IllegalArgumentException("Invalid position (ReedSolomonDecoder)"); received[position] = GF256::addOrSubtract(received[position], errorMagitudes[i]); } }
void ReedSolomonDecoder::decode(ArrayRef<int> received, int twoS) { Ref<GF256Poly> poly(new GF256Poly(field, received)); #ifdef DEBUG cout << "decoding with poly " << *poly << "\n"; #endif ArrayRef<int> syndromeCoefficients(new Array<int>(twoS)); #ifdef DEBUG cout << "syndromeCoefficients array = " << syndromeCoefficients.array_ << "\n"; #endif bool noError = true; for (int i = 0; i < twoS; i++) { int eval = poly->evaluateAt(field.exp(i)); syndromeCoefficients[syndromeCoefficients->size() - 1 - i] = eval; if (eval != 0) { noError = false; } } if (noError) { return; } Ref<GF256Poly> syndrome(new GF256Poly(field, syndromeCoefficients)); Ref<GF256Poly> monomial(field.buildMonomial(twoS, 1)); vector<Ref<GF256Poly> > sigmaOmega (runEuclideanAlgorithm(monomial, syndrome, twoS)); ArrayRef<int> errorLocations = findErrorLocations(sigmaOmega[0]); ArrayRef<int> errorMagitudes = findErrorMagnitudes(sigmaOmega[1], errorLocations); for (unsigned i = 0; i < errorLocations->size(); i++) { int position = received->size() - 1 - field.log(errorLocations[i]); received[position] = GF256::addOrSubtract(received[position], errorMagitudes[i]); } }