A listing of the code is below:
public class Crc16Ccitt
{
     const ushort poly = 4129;
     ushort[] table = new ushort[256];
     ushort initialValue = 0;
     public ushort ComputeChecksum(byte[] bytes)
     {
        ushort crc = this.initialValue;
        for (int i = 0; i <>
                {
           crc = (ushort)((crc <<>> 8) ^ (0xff & bytes[i]))]);
        }
        return crc;
     }
     public byte[] ComputeChecksumBytes(byte[] bytes)
     {
        ushort crc = ComputeChecksum(bytes);
        return new byte[] { (byte)(crc >> 8), (byte)(crc & 0x00ff) };
     }
     public Crc16Ccitt(InitialCrcValue initialValue)
     {
        this.initialValue = (ushort)initialValue;
        ushort temp, a;
        for (int i = 0; i <>
        {
           temp = 0;
           a = (ushort)(i <<>
           for (int j = 0; j <>
           {
              if (((temp ^ a) & 0x8000) != 0)
              {
                 temp = (ushort)((temp <<>
              }
              else
              {
                 temp <<= 1;
              }
              a <<= 1;
              }
              table[i] = temp;
           }
        }
     }
}
Here is the code I wrote to produce the result:
System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
byte[] byteKey = encoding.GetBytes(strKey);
Crc16Ccitt crcChecksum = new Crc16Ccitt(InitialCrcValue.NonZero1);
intCheckSumReturn = crcChecksum.ComputeChecksum(byteKey);
byte[] byteKey = encoding.GetBytes(strKey);
Crc16Ccitt crcChecksum = new Crc16Ccitt(InitialCrcValue.NonZero1);
intCheckSumReturn = crcChecksum.ComputeChecksum(byteKey);
No comments:
Post a Comment