轉載自 這裡
前言 :
CRC is a "digital fingerprint" of a file.
With CRC32 you can get a single 32-bit number that represents a string or file (of any size). If the file data changes in any way (even a single bit) the CRC32 calculation would yield a completely different value. This algorithm is used by WinZip and PKZIP (ie the same numbers are generated) so:
pkunzip.exe -vt File.zip gives the same CRC value as you get by giving the file to this code.
A single 1kB table is allocated while instances of CCRC32 exist.
使用範例 :
你可以直接將 Buffer/Content 傳進 CCRC32 From 函式運算 CRC Code :
或透過由 CCRC32 建立的物件操作 :
如果來源是檔案, 你可以這麼做 :
事實上, 你也可以將檔案開啟, 讀取與關閉交給 CRC32 類別處理, 而直接將檔案路徑傳入 :
CRC32實作代碼 :
底下是 CRC32 類別實作的標頭檔 :
前言 :
CRC is a "digital fingerprint" of a file.
With CRC32 you can get a single 32-bit number that represents a string or file (of any size). If the file data changes in any way (even a single bit) the CRC32 calculation would yield a completely different value. This algorithm is used by WinZip and PKZIP (ie the same numbers are generated) so:
pkunzip.exe -vt File.zip gives the same CRC value as you get by giving the file to this code.
A single 1kB table is allocated while instances of CCRC32 exist.
使用範例 :
你可以直接將 Buffer/Content 傳進 CCRC32 From 函式運算 CRC Code :
- DWORD CRC=CCRC32().From(Buffer,Size);
- CCRC32 CRC32;
- DWORD CRC1=CRC32.From(Buffer1,Size1);
- DWORD CRC2=CRC32.From(Buffer2,Size2);
- int OK;
- CCRC32 CRC32;
- BYTE Buffer[1024];
- FILE* File=fopen("C:\\CheckMe.txt","rb");
- if(File) do CRC32.From(Buffer, OK=fread(Buffer, 1, 1024, File), true); while(OK);
- fclose(File);
- DWORD CRC=CRC32.GetCRC();
- DWORD CRC=CCRC32().From("C:\\CheckMe.txt");
底下是 CRC32 類別實作的標頭檔 :
This message was edited 1 time. Last update was at 14/03/2011 15:21:39
沒有留言:
張貼留言