CRC32
Algorithm
Site Map Feedback

Download:

Up Adler32 CRC32 MD5 Roller32

Cyclic Redundancy Check

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.

Usage:
  DWORD CRC=CCRC32().From(Buffer,Size);
or use one instance for several CRCs:
  CCRC32 CRC32;
  DWORD CRC1=CRC32.From(Buffer1,Size1);
  DWORD CRC2=CRC32.From(Buffer2,Size2);
or if reading data in blocks:
  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();
But since we want the fastest routines we should use CreateFile and that's what the class uses internally for retrieving the CRC32 of a file:
  DWORD CRC=CCRC32().From("C:\\CheckMe.txt");

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


 (2114) Last modified: Thu, 05 Feb 2009 19:11:42 +0000