Ejemplo n.º 1
0
        public void SimplyDecodeRawBytesArray(int[] modifiedData, int[] data)
        {
            var processedBytes = 0;

            for (var i = 0; i < modifiedData.Length; i += _messageLength)
            {
                var tempData = new int[_messageLength];

                var remainder = (modifiedData.Length - i < _messageLength) ? modifiedData.Length - i : _messageLength;

                for (var j = 0; j < remainder; j++)
                {
                    tempData[j] = modifiedData[i + j];
                }

                _simpleRsDecoder.Decode(tempData, _correctionLength);

                remainder = remainder >= (data.Length - processedBytes)
                    ? (data.Length - processedBytes)
                    : _informationLength;

                for (var j = 0; j < remainder; j++)
                {
                    data[processedBytes + j] = tempData[j];
                }
                processedBytes += _informationLength;
            }
        }
Ejemplo n.º 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]);
                    }
                }
            }
        }
Ejemplo n.º 3
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]);
            }
        }
Ejemplo n.º 4
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]);
                    }
                }
            }
        }
Ejemplo n.º 5
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]);
                }
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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]);
            }
        }