1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // Crc64.cpp : 定义 DLL 应用程序的导出函数。
- //
- //#include "stdafx.h"
- #include "Crc64.h"
- #ifdef OLDCRC
- #define POLY64REV 0xd800000000000000ULL
- #define INITIALCRC 0x0000000000000000ULL
- #else
- #define POLY64REV 0x95AC9329AC4BC9B5ULL
- #define INITIALCRC 0xFFFFFFFFFFFFFFFFULL
- #define POLY32REV 0xEDB88320
- #define INITIALCRC32 (0xFFFFFFFF)
- #endif
- int crc32_table[256];
- unsigned long long CRCTable[256] = { 0 };
- // 这是已导出类的构造函数。
- // 有关类定义的信息,请参阅 Crc64.h
- CCrc64::CCrc64()
- {
- int i, j;
- unsigned long long part;
- for (i = 0; i < 256; i++)
- {
- part = i;
- for (j = 0; j < 8; j++)
- {
- if (part & 1)
- part = (part >> 1) ^ POLY64REV;
- else
- part >>= 1;
- }
- CRCTable[i] = part;
- }
- return;
- }
- CCrc32::CCrc32()
- {
- int c;
- int i = 0;
- int bit = 0;
- for (i = 0; i < 256; i++)
- {
- c = (int)i;
- for (bit = 0; bit < 8; bit++)
- {
- if (c & 1)
- {
- c = (c >> 1) ^ (POLY32REV);
- }
- else
- {
- c = c >> 1;
- }
- }
- crc32_table[i] = c;
- }
- }
- CCrc64 g_C_C_r_c_64;//useless .
- CCrc32 g_C_C_r_c_32;//useless .
- CRC64_API int GetCrc32(const char *pSrc, size_t size)
- {
- int crc = INITIALCRC32;
- while (size--)
- crc = (crc >> 8) ^ (crc32_table[(crc ^ *pSrc++) & 0xff]);
- return crc;
- }
- CRC64_API UINT64 GetCrc64(const char *pSrc, DWORD size)
- {
- unsigned long long crc = INITIALCRC;
- for (DWORD i = 0; i < size; i++)
- {
- crc = CRCTable[(crc ^ pSrc[i]) & 0xff] ^ (crc >> 8);
- }
- return crc;
- }
|