Using system;
Using system. Collections. Generic;
Using system. text;
Namespace Test
{
Class CRC
{
///
/// Get the CRC Check value of a byte array
///
///Byte array
/// CRC Check Value
Public static int getkey (byte [] data)
{
Int COUNT = data. length;
Byte [] buffer = new byte [data. Length + 2];
Data. copyto (buffer, 0 );
Int PTR = 0;
Int I = 0;
Int CRC = 0;
Byte crc1, crc2, crc3;
Crc1 = buffer [PTR ++];
Crc2 = buffer [PTR ++];
Buffer [count] = 0;
Buffer [count + 1] = 0;
While (-- count> = 0)
{
Crc3 = buffer [PTR ++];
For (I = 0; I {
If (crc1 & 0x80)> 7) = 1) // judge whether the high position of crc1 is 1
{
Crc1 = (byte) (crc1
If (crc2 & 0x80)> 7) = 1) // judge whether the high position of crc2 is 1
{
Crc1 = (byte) (crc1 | 0x01); // the low position of crc1 is changed from 0 to 1.
}
Crc2 = (byte) (crc2
If (crc3 & 0x80)> 7) = 1) // judge whether the high position of crc3 is 1
{
Crc2 = (byte) (crc2 | 0x01); // the low position of crc2 is changed from 0 to 1.
}
Crc3 = (byte) (crc3
Crc1 = (byte) (crc1 ^ 0x10 );
Crc2 = (byte) (crc2 ^ 0x21 );
}
Else
{
Crc1 = (byte) (crc1
If (crc2 & 0x80)> 7) = 1) // judge whether the high position of crc2 is 1
{
Crc1 = (byte) (crc1 | 0x01); // the low position of crc1 is changed from 0 to 1.
}
Crc2 = (byte) (crc2
If (crc3 & 0x80)> 7) = 1) // judge whether the high position of crc3 is 1
{
Crc2 = (byte) (crc2 | 0x01); // the low position of crc2 is changed from 0 to 1.
}
Crc3 = (byte) (crc3}
}
}
CRC = (INT) (crc1
Return CRC;
}
}< BR >}< br>