Builds a crc32 table given a polynomial - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:CRC

Description

Builds a crc32 table given a polynomial

Demo Code

//              Copyright (c) 2006-2017 All Rights reserved                   *
using System.Security.Cryptography;
using System.IO;//from   w ww. j a v  a  2s . c  om
using System.Collections;

public class Main{
        /// <summary>
      /// Builds a crc32 table given a polynomial
      /// </summary>
      /// <param name="ulPolynomial"></param>
      /// <returns></returns>
      protected static uint[] BuildCRC32Table( uint ulPolynomial )
      {
         uint dwCrc;
         var table = new uint[256];

         // 256 values representing ASCII character codes. 
         for (var i = 0; i < 256; i++)
         {
            dwCrc = (uint)i;
            for (var j = 8; j > 0; j--)
            {
               if((dwCrc & 1) == 1)
                  dwCrc = (dwCrc >> 1) ^ ulPolynomial;
               else
                  dwCrc >>= 1;
            }
            table[i] = dwCrc;
         }

         return table;
      }
}

Related Tutorials