home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / crcksrc.zip / crc24.h < prev    next >
Text File  |  1995-02-15  |  2KB  |  65 lines

  1. /*
  2. $Header: e:/work2/x/jacquard/src/control/RCS/crc24.h 1.2 93/06/23 03:21:13 m3m rel $
  3. **
  4. ** Copyright M CUBED 1993, ALL RIGHTS DESERVED
  5. ** This work is derived in part from public domain code, and is contributed
  6. ** back to the public domain.
  7. **
  8. ** purpose  : calculates a 24 bit cyclic redundancy check to verify file
  9. **            integrity; the value of the original file must be known to
  10. **            check for corruption; note that you can also check files
  11. **            with different names to check if contents are the same only
  12. **            the contents of the file are checked, the file name has no
  13. **            bearing on the crc value.
  14. **
  15. **            Certainty is 'quite high' that the files are identical if
  16. **            the 24 bit crc value is identical (CCITT uses only a 16 bit
  17. **            crc which is commonly considered acceptable verification of
  18. **            accurate data transmissions). I do not know what the
  19. **            percentages are.
  20. **
  21. ** author   : Michael McDaniel
  22. **
  23. ** reference: 1) pgp21, armor.c
  24. **            2) "C Programmer's Guide to Serial Communications",
  25. **               by Joe Campbell
  26. **               These CRC functions are derived from code in chapter 19
  27. **               Generalized to any CRC width by Philip Zimmermann; 24 bit
  28. **               width used here.
  29. **
  30. */
  31.  
  32. # ifdef __CRC24_CPP_
  33.    static char crc24_h_rcsid[] = "$Header: e:/work2/x/jacquard/src/control/RCS/crc24.h 1.2 93/06/23 03:21:13 m3m rel $";
  34. # endif
  35.  
  36.  
  37. typedef unsigned long crcword;
  38.  
  39.  
  40. class crc24
  41. {
  42.    public:
  43.       crc24( char * file_name );
  44.       ~crc24();
  45.  
  46.       unsigned long value();                     // returns calculated value
  47.  
  48.       int valid() { return pvalid; };
  49.  
  50.  
  51.    private:
  52.       crcword  accum;
  53.       int      pvalid;                    // 1 if successful calculation
  54.                                          // i.e. file could be opened, read,
  55.                                         // enough memory for calculation
  56.  
  57.       void     mk_crctbl( crcword poly );
  58.       crcword  crchware(unsigned char ch, crcword poly, crcword accum);
  59.       crcword  crcupdate(unsigned char data, crcword accum);
  60.  
  61. }; // end crc24
  62.  
  63. // end $Source: e:/work2/x/jacquard/src/control/RCS/crc24.h $
  64.  
  65.