0x00000000)] // http://crccalc.com says the value should be 0xD202EF8D, however logic says it must be incorrect public void Crc32_ChainingSamples(String input, UInt32 expected) { var output = CrcAlgorithm.CreateCrc32() .Append(Encoding.ASCII.GetBytes(input)) .ToUInt64(); Assert.Equal(expected, output); }
0xFFFF)] // http://crccalc.com says the value should be 0xE1F0, however logic says it must be incorrect public void Crc16CittFalse_Samples(String input, UInt16 expected) { var crc = CrcAlgorithm.CreateCrc16CcittFalse(); crc.Append(Encoding.ASCII.GetBytes(input)); var output = crc.ToUInt64(); Assert.Equal(expected, output); }
public void Crc16XModem() { String expected; String output; var crc = CrcAlgorithm.CreateCrc16Xmodem(); // 0 bytes expected = Crc16Ccitt.ComputeInteger(new Byte[] { }).ToHexString(2); output = crc.ToHexString(); Assert.Equal(expected, output); // 1 byte complete for (Byte i = 0; i < Byte.MaxValue; i++) { // Compute expected expected = Crc16Ccitt.ComputeInteger(new[] { i }).ToHexString(2); // Compute actual crc.Append(new Byte[] { i }); output = crc.ToHexString(); crc.Clear(); // Compare Assert.Equal(expected, output); } // 2 byte complete for (Byte i = 0; i < Byte.MaxValue; i++) { for (Byte j = 0; j < Byte.MaxValue; j++) { // Compute expected expected = Crc16Ccitt.ComputeInteger(new[] { i, j }).ToHexString(2); // Compute actual crc.Append(new[] { i, j }); output = crc.ToHexString(); crc.Clear(); // Compare Assert.Equal(expected, output); } } // 3-256 byte for (Byte length = 0; length < Byte.MaxValue; length++) { for (Byte b = 0; b < Byte.MaxValue; b++) { var input = new Byte[length]; for (var i = 0; i < input.Length; i++) { input[i] = b; } // Compute expected expected = Crc16Ccitt.ComputeInteger(input).ToHexString(2); // Compute actual crc.Append(input); output = crc.ToHexString(); crc.Clear(); // Compare Assert.Equal(expected, output); } } }