Beispiel #1
0
        public void ProperlyCorrectsErrorInAMessage2()
        {
            var reedSolomon = new ReedSolomon();
            var data        = new int[223];

            for (var i = 0; i < 223; i++)
            {
                data[i] = i + 10;
            }

            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            modifiedData[12] += 87;

            var simpleDecoder = new SimpleRSDecoder(GenericGF.DATA_MATRIX_FIELD_256);

            var response = simpleDecoder.Decode(modifiedData, 32);

            Assert.IsTrue(response);

            for (var i = 0; i < 223; i++)
            {
                Assert.AreEqual(data[i], modifiedData[i]);
            }
        }
Beispiel #2
0
        public void ProperlyCorrectsErrorInAMessageLoop()
        {
            var random = new Random(1);

            for (var j = 0; j < 10;)
            {
                var reedSolomon = new ReedSolomon();
                var data        = new int[223];

                for (var i = 0; i < 223; i++)
                {
                    data[i] = random.Next(1, 255);
                }

                var modifiedData = reedSolomon.EncodeRawBytesArray(data);

                var modifIndex = random.Next(255);
                modifiedData[modifIndex] = random.Next(255);

                var simpleDecoder = new SimpleRSDecoder(GenericGF.DATA_MATRIX_FIELD_256);

                var response = simpleDecoder.Decode(modifiedData, 32);

                if (response)
                {
                    j++;
                    for (var i = 0; i < 223; i++)
                    {
                        Assert.AreEqual(data[i], modifiedData[i]);
                    }
                }
            }
        }
Beispiel #3
0
        public void LongDivideProperlyCorrectsErrorInAMessage4()
        {
            var reedSolomon = new ReedSolomon();
            var data        = new int[223];

            for (var i = 0; i < 223; i++)
            {
                data[i] = ((i + 50) % 255) + 1;
            }

            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            modifiedData[0]  = 1;
            modifiedData[15] = 16;

            var simpleDecoder = new SimpleRSDecoder(GenericGF.DATA_MATRIX_FIELD_256);

            var response = simpleDecoder.LongDecode(modifiedData, 32);

            Assert.IsTrue(response);

            for (var i = 0; i < 223; i++)
            {
                Assert.AreEqual(data[i], modifiedData[i]);
            }
        }
Beispiel #4
0
 public ReedSolomon(GenericGF galoisField, int correctionBytes)
 {
     _messageLength      = galoisField.Size - 1;
     _correctionLength   = correctionBytes;
     _informationLength  = _messageLength - _correctionLength;
     _reedSolomonEncoder = new ReedSolomonEncoder(galoisField);
     _reedSolomonDecoder = new ReedSolomonDecoder(galoisField);
     _simpleRsDecoder    = new SimpleRSDecoder();
 }
Beispiel #5
0
        public ReedSolomon(int correctionBytes)
        {
            var galoisField = GenericGF.DATA_MATRIX_FIELD_256;

            _messageLength      = galoisField.Size - 1;
            _correctionLength   = correctionBytes;
            _informationLength  = _messageLength - _correctionLength;
            _reedSolomonEncoder = new ReedSolomonEncoder(galoisField);
            _reedSolomonDecoder = new ReedSolomonDecoder(galoisField);
            _simpleRsDecoder    = new SimpleRSDecoder();
        }
Beispiel #6
0
        public void ProperlyCorrects2ErrorsInAMessageLoop()
        {
            var random = new Random(1);

            for (var j = 0; j < 5;)
            {
                var reedSolomon = new ReedSolomon();
                var data        = new int[223];

                for (var i = 0; i < 223; i++)
                {
                    data[i] = random.Next(1, 255);
                }

                var modifiedData = reedSolomon.EncodeRawBytesArray(data);

                var modifIndex = random.Next(255);
                var modifValue = random.Next(255);
                while (modifValue == modifiedData[modifIndex])
                {
                    modifValue = random.Next(255);
                }
                modifiedData[modifIndex] = modifValue;

                var modifIndex2 = random.Next(255);
                var modifValue2 = random.Next(255);
                while (modifIndex == modifIndex2)
                {
                    modifIndex2 = random.Next(255);
                }
                while (modifValue2 == modifiedData[modifIndex2])
                {
                    modifValue2 = random.Next(255);
                }
                modifiedData[modifIndex2] = modifValue2;

                var simpleDecoder = new SimpleRSDecoder(GenericGF.DATA_MATRIX_FIELD_256);

                var response = simpleDecoder.Decode(modifiedData, 32);

                var bytesDiffCount = GetDiffTable(data, modifiedData, 223);

                Assert.IsTrue(bytesDiffCount.Count <= 2);
                if (response)
                {
                    j++;
                    for (var i = 0; i < 223; i++)
                    {
                        Assert.AreEqual(data[i], modifiedData[i]);
                    }
                }
            }
        }
Beispiel #7
0
        public void ProperlyCorrectsUpto16ErrorsInAMessageLoop()
        {
            var random = new Random(1);

            for (var j = 0; j < 17; j++)
            {
                var reedSolomon = new ReedSolomon();
                var data        = new int[223];

                for (var i = 0; i < 223; i++)
                {
                    data[i] = random.Next(255);
                }

                var modifiedData = reedSolomon.EncodeRawBytesArray(data);
                var errorCount   = 0;

                var startIndex = random.Next(0, 255 - 16);
                for (var k = startIndex; k < startIndex + j; k++)
                {
                    var modifValue = random.Next(255);
                    while (modifValue == modifiedData[k])
                    {
                        modifValue = random.Next(255);
                    }
                    modifiedData[k] = modifValue;
                    errorCount++;
                }

                var simpleDecoder = new SimpleRSDecoder(GenericGF.DATA_MATRIX_FIELD_256);

                var response = simpleDecoder.Decode(modifiedData, 32);

                var bytesDiffCount = GetDiffTable(data, modifiedData, 223);

                Assert.IsTrue(bytesDiffCount.Count <= errorCount);

                for (var i = 0; i < 223; i++)
                {
                    Assert.AreEqual(data[i], modifiedData[i]);
                }
            }
        }
Beispiel #8
0
        public void ProperlyNotCorrectsErrorInAMessage5()
        {
            var reedSolomon = new ReedSolomon();
            var data        = new int[223];

            for (var i = 0; i < 223; i++)
            {
                data[i] = ((i + 50) % 255) + 1;
            }

            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            modifiedData[0]   = 0;
            modifiedData[170] = 170;

            var simpleDecoder = new SimpleRSDecoder(GenericGF.DATA_MATRIX_FIELD_256);

            var response = simpleDecoder.Decode(modifiedData, 32);

            Assert.IsFalse(response);
        }
Beispiel #9
0
        public void ProperlyFindsErrorInAMessage()
        {
            var reedSolomon = new ReedSolomon(32);
            var data        = new int[223];

            for (var i = 0; i < 223; i++)
            {
                data[i] = i + 10;
            }

            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            for (var i = 10; i < 30; i++)
            {
                modifiedData[i] = i + 5;
            }

            var simpleDecoder = new SimpleRSDecoder();

            var response = simpleDecoder.Decode(modifiedData, 32);

            Assert.IsFalse(response);
        }
Beispiel #10
0
        public void ProperlyDecodesNoErrorMessage()
        {
            var reedSolomon = new ReedSolomon(32);
            var data        = new int[223];

            for (var i = 0; i < 223; i++)
            {
                data[i] = i + 10;
            }

            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            var simpleDecoder = new SimpleRSDecoder();

            var response = simpleDecoder.Decode(modifiedData, 32);

            Assert.IsTrue(response);

            for (var i = 0; i < 223; i++)
            {
                Assert.AreEqual(data[i], modifiedData[i]);
            }
        }