CRC

CRC is one of the most reliable error detection schemes and can detect up to 95.5% of all errors. The most commonly used code is the CRC-32 standard code which is defined by the CCITT, and will give a 32-bit CRC signature (8 hex characters). This signature is normally appended onto the data, and then checked when the data is read. If the CRC-32 check differs from the stored value, there is likely to be an error in the data. [Theory]

The basic idea of a CRC can be illustrated using an example. Suppose the transmitter and receiver were both to agree that the numerical value sent by the transmitter would always be divisible by 9. Then should the receiver get a value which was not divisible by 9 would know it knows that there had been an error. For example, if a value of 32 were to be transmitted it could be changed to 320 so that the transmitter would be able to add to the least significant digit, making it divisible by 9. In this case the transmitter would add 4, making 324. If this transmitted value were to be corrupted in transmission then there would only be a 10% chance that an error would not be detected.

  • Try “The quick brown fox jumps over the lazy dog”. Try!, which should give a CRC-32 value of: 414fa339 Check
  • Try “Test vector from febooti.com”. Try!, which should give a CRC-32 value of: 0c877f61Check
  • Try “”. Try!, which should give a CRC-32 value of 00000000 Check

Coding

The code I have used is:

       public void checkCrc(string message)
        {
            Crc32 crc32 = new Crc32();
            String hash = String.Empty;
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte [] data = encoding.GetBytes(message);

                foreach (byte b in crc32.ComputeHash(data)) hash += b.ToString("x2").ToLower();
                hash1 = hash;
        }

which makes a call to the code used in:

http://damieng.com/blog/2006/08/0/calculating_crc32_in_c_and_net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s