Пример #1
0
        /*******************************************/
        /// <summary>
        /// This function returns the byte array included crc32 value.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="type">This parameter means crc32 algorithm type.</param>
        /// <returns></returns>
        /*******************************************/
        public static IEnumerable <byte> WithCRC32(this IEnumerable <byte> data, CRC32Type type = CRC32Type.Basic)
        {
            if (type == CRC32Type.Basic)
            {
                return(data.AppendRange(BitConverter.GetBytes(data.CRC32(type))));
            }

            return(new List <byte>());
        }
Пример #2
0
        /*******************************************/
        /// <summary>
        /// This function returns the CRC32 value
        /// </summary>
        /// <param name="data"></param>
        /// <param name="type">This parameter means crc32 algorithm type.</param>
        /// <returns></returns>
        /*******************************************/
        public static uint CRC32(this IEnumerable <byte> data, CRC32Type type = CRC32Type.Basic)
        {
            uint result = 0;

            if (type == CRC32Type.Basic)
            {
                result = CRC.ComputeCRC32(data);
            }

            return(result);
        }
Пример #3
0
 private static void TestCRC32(CRC32Type type, params IEnumerable <byte>[] testValues)
 {
     foreach (var testValue in testValues)
     {
         Console.WriteLine("------------------------------------------------------------------");
         Console.WriteLine($"CRC32 [{type}] test for source [{testValue.ToHexString()}]");
         Console.WriteLine($"crc is 0x{testValue.CRC32(type).ToString("x8")}");
         Console.WriteLine($"source + crc is 0x{testValue.WithCRC32(type).ToHexString()}");
         Console.WriteLine("------------------------------------------------------------------");
     }
 }