public void RoundTripTest() { for( int i = 0; i < message.Length; i++ ) { // message[i] must be elements of the field. If size = 16, field elements are 0 .. 15. // rand.Next(0, 16) returns elements between 0 .. 15 message[i] = (byte)rand.Next( 0, (int)size ); } // ---- Encode the message ---- watch.Start(); encoder.Encode( message ); watch.Stop(); Array.Copy( message, cleanMessage, message.Length ); // ---- Corrupt the TX message ---- int corruptPosition; for( int i = 0; i < maxCorruption; i++ ) { corruptPosition = rand.Next( 0, message.Length ); message[corruptPosition] = (byte)rand.Next( 0, (int)size ); } // ---- Repair the message ---- watch.Start(); decoder.Decode( message ); watch.Stop(); // ---- Compare ---- ArrayHelpers.CheckArrayEquals( message, cleanMessage ); }
public static void EncoderTest() { Rs256Encoder encoder = new Rs256Encoder( 16, 11, 0x13 ); byte[] message = { 0, 0, 0, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; byte[] encodedMessage = { 12, 12, 3, 3, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; encoder.Encode( message ); ArrayHelpers.CheckArrayEquals( message, encodedMessage ); }