Beispiel #1
0
 public static int[] CalculateSyndromes(GaloisFieldPolynomial poly, int numberOfSyndromes)
 {
     int[] syndromes = new int[numberOfSyndromes];
     for (int i = 0; i < numberOfSyndromes; i++)
     {
         syndromes[i] = poly.EvaluateAt(_galoisField.Exp(i));
     }
     return syndromes;
 }
Beispiel #2
0
        public static int[] CorrectErrors(GaloisFieldPolynomial poly, int[] syndromes, int[] positions)
        {
            List<int> q = new List<int>();
            q.Add(1);

            int positionsCount = positions.Length;
            int polyLength = poly.Coefficients.Length;
            for (int i = 0; i < positionsCount; i++)
            {
                int x = _galoisField.Exp(polyLength - 1 - positions[i]);
                q = GaloisFieldPolynomial.Multiply(q, new List<int>(new int[] { x, 1 }));
            }
            List<int> p = new List<int>();
            for (int i = 0; i < positionsCount; i++)
            {
                p.Add(syndromes[i]);
            }
            p.Reverse();
            p = GaloisFieldPolynomial.Multiply(p, q);
            int pLength = p.Count;
            List<int> pTemp = new List<int>();
            for (int i = pLength - positionsCount; i < pLength; i++)
            {
                pTemp.Add(p[i]);
            }
            p = pTemp;
            int qLength = q.Count;
            int currentQPosition = 0;
            if (qLength % 2 != 0) currentQPosition++;
            List<int> qTemp = new List<int>();
            for (; currentQPosition < qLength; currentQPosition += 2)
            {
                qTemp.Add(q[currentQPosition]);
            }
            q = qTemp;
            int[] correctedOutput = new int[polyLength];

            for (int i = 0; i < positionsCount; i++)
            {
                int x = _galoisField.Exp(positions[i] + 256 - polyLength);
                int y = GaloisFieldPolynomial.Evaluate(p, x);
                int z = GaloisFieldPolynomial.Evaluate(q, _galoisField.Multiply(x, x));
                correctedOutput[positions[i]] ^= _galoisField.Divide(y, _galoisField.Multiply(x, z));
            }

            return correctedOutput;
        }