📄 _crc32.cpp
字号:
//---------------------------------------------------------------------------
#pragma hdrstop
#include "_CRC32.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
void TCRC32::Init_CRC32_Table(void)
{
//TODO: Add your source code here
// This is the official polynomial used by CRC-32 in PKZip, WinZip and Ethernet.
unsigned long ulPolynomial = 0x04c11db7;
// 256 values representing ASCII character codes.
for(int i = 0; i <= 0xFF; i++)
{
crc32_table[i]=Reflect(i, 8) << 24;
for (int j = 0; j < 8; j++)
crc32_table[i] = (crc32_table[i] << 1) ^ (crc32_table[i] & (1 << 31) ? ulPolynomial : 0);
crc32_table[i] = Reflect(crc32_table[i], 32);
}
}
__fastcall TCRC32::TCRC32()
{
//TODO: Add your source code here
Init_CRC32_Table();
}
__fastcall TCRC32::~TCRC32()
{
//TODO: Add your source code here
}
// This function uses the crc32_table lookup table to generate a CRC for csData
int TCRC32::Get_CRC(unsigned char * buffer, int dwSize)
{
//TODO: Add your source code here
// Be sure to use unsigned variables,
// because negative values introduce high bits
// where zero bits are required.
unsigned long crc(0xffffffff);
int len;
len = dwSize;
// Perform the algorithm on each character
// in the string, using the lookup table values.
while(len--)
crc = (crc >> 8) ^ crc32_table[(crc & 0xFF) ^ *buffer++];
// Exclusive OR the result with the beginning value.
return crc^0xffffffff;
}
// Reflection is a requirement for the official CRC-32 standard.
// You can create CRCs without it, but they won't conform to the standard.
unsigned long TCRC32::Reflect(unsigned long ref, unsigned char ch)
{
//TODO: Add your source code here
// Used only by Init_CRC32_Table()
unsigned long value(0);
// Swap bit 0 for bit 7 , bit 1 for bit 6, etc.
for(int i = 1; i < (ch + 1); i++)
{
if(ref & 1)
value |= 1 << (ch - i);
ref >>= 1;
}
return value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -