public void Test7() { var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); var encoder = new Rs256EncoderLittleEndian(64, 60, new GaloisField256(0x11D)); ReadOnlySpan <byte> largeEncodedData = LargeEncodedData; var rand = new Random(1); for (var i = 1; i < 64; ++i) { Span <byte> testData = stackalloc byte[largeEncodedData.Length + i]; var randBytes = new byte[i]; rand.NextBytes(randBytes); largeEncodedData.CopyTo(testData); new Span <byte>(randBytes).CopyTo(testData.Slice(largeEncodedData.Length)); Rs256Algorithms.RemoveAndCorrectFecInPlace(ref testData, encoder, decoder, largeEncodedData.Length - 4, 4, out _); // There are 4 junk bytes at then end. The other 4 is for possible MIC32 Assert.That(testData.Length, Is.EqualTo(LargeDecodedData.Length)); //Assert.That(testData.SequenceEqual(LargeDecodedData)); Assert.That(testData.ToArray(), Is.EqualTo(LargeDecodedData)); } }
public void TestCouldFailInLambdaButOK() { var data = new byte[24]; var rand = new Random(1); rand.NextBytes(data); var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); decoder.CorrectInPlace(data); }
public void TestFailedBeforeCorrectionInCalcLambda() { var data = new byte[24]; for (var i = 0; i < data.Length; ++i) { data[i] = (byte)(i + 4); } var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); decoder.CorrectInPlace(data); }
public void Test6() { var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); var encoder = new Rs256EncoderLittleEndian(64, 60, new GaloisField256(0x11D)); ReadOnlySpan <byte> data = LargeEncodedData; Span <byte> testData = data.ToArray(); Rs256Algorithms.RemoveAndCorrectFecInPlace(ref testData, encoder, decoder, data.Length - 4, 4, out _); // There are 4 junk bytes at then end. The other 4 is for possible MIC32 Assert.That(testData.Length, Is.EqualTo(2590)); Assert.That(testData.SequenceEqual(LargeDecodedData)); }
public void Test5() { var data = new byte[52 + 4] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0xE4, 0x81, 0x13, 0xE0, 0x79, 0x9b, 0x9a, 0xee }; var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); var encoder = new Rs256EncoderLittleEndian(64, 60, new GaloisField256(0x11D)); int MaxExtraBytes = 64 - data.Length; var rand = new Random(1); var randbytes = new byte[MaxExtraBytes]; int searchCount = 100; var results = new Rs256Algorithms.FixedList <int>(stackalloc int[64]); for (var i = 0; i < searchCount; ++i) { rand.NextBytes(randbytes); var tooLongData = new byte[data.Length + MaxExtraBytes]; Buffer.BlockCopy(data, 0, tooLongData, 0, data.Length); Buffer.BlockCopy(randbytes, 0, tooLongData, data.Length, MaxExtraBytes); var testData = new Span <byte>(tooLongData, 0, tooLongData.Length); Rs256Algorithms.SearchLengths(testData, encoder, decoder, ref results); Assert.That(results.ToArray(), Does.Contain(data.Length)); if (results.Length > 1) { Console.WriteLine($"Found {results.Length} possibilities: {string.Join(", ", results.ToArray())}"); } results.Clear(); } }
public void TestCannotFail() { var data = new byte[52 + 4] { 0xFF, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0xFF, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0xFF, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0xFF, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0xE4, 0x81, 0x13, 0xE0, 0x79, 0x9b, 0x9a, 0xee }; var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); decoder.CorrectInPlace(data); }
private byte[] CorrectWithChecksum(byte[] data, byte[] checksum) { var plainData = new byte[data.Length + checksum.Length]; Buffer.BlockCopy(data, 0, plainData, 0, data.Length); Buffer.BlockCopy(checksum, 0, plainData, data.Length, checksum.Length); var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); decoder.CorrectInPlace(plainData); var outBytes = new byte[data.Length]; Buffer.BlockCopy(plainData, 0, outBytes, 0, outBytes.Length); return(outBytes); }
public void Test2() { var data = new byte[] { 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x9E, 0x26, 0x55, 0x71 }; var checksum = CreateChecksum(data); Assert.That(checksum, Is.EqualTo(new byte[] { 0xfe, 0xd7, 0x4a, 0xfe })); var toBeCorrected = (byte[])data.Clone(); toBeCorrected[0] = 255; toBeCorrected[2] = 255; toBeCorrected[5] = 255; toBeCorrected[6] = 255; var plainData = new byte[data.Length + checksum.Length]; Buffer.BlockCopy(data, 0, plainData, 0, data.Length); Buffer.BlockCopy(checksum, 0, plainData, data.Length, checksum.Length); var decoder = new Rs256DecoderLittleEndian(64, 60, new GaloisField256(0x11D)); decoder.CorrectInPlace(plainData); decoder.CorrectInPlace(plainData); var corrected = new byte[data.Length]; Buffer.BlockCopy(plainData, 0, corrected, 0, corrected.Length); Assert.That(corrected, Is.EqualTo(data)); }