home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs_src.exe / SBBS / SMB / CRC16.C next >
Encoding:
C/C++ Source or Header  |  1997-04-13  |  1.0 KB  |  40 lines

  1. /* CRC16.C */
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. /* 16-bit CRC routines */
  6.  
  7. #include "smblib.h"
  8.  
  9. /****************************************************************************/
  10. /* Updates 16-bit "rcrc" with character 'ch'                                */
  11. /****************************************************************************/
  12. void ucrc16(uchar ch, ushort *rcrc) {
  13.     ushort i, cy;
  14.     uchar nch=ch;
  15.  
  16. for (i=0; i<8; i++) {
  17.     cy=*rcrc & 0x8000;
  18.     *rcrc<<=1;
  19.     if (nch & 0x80) *rcrc |= 1;
  20.     nch<<=1;
  21.     if (cy) *rcrc ^= 0x1021; }
  22. }
  23.  
  24. /****************************************************************************/
  25. /* Returns 16-crc of string (not counting terminating NULL)                 */
  26. /****************************************************************************/
  27. ushort SMBCALL crc16(char *str)
  28. {
  29.     int     i=0;
  30.     ushort  crc=0;
  31.  
  32. ucrc16(0,&crc);
  33. while(str[i])
  34.     ucrc16(str[i++],&crc);
  35. ucrc16(0,&crc);
  36. ucrc16(0,&crc);
  37. return(crc);
  38. }
  39.  
  40.