home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
c
/
cuj9301.zip
/
1101068A
< prev
next >
Wrap
Text File
|
1992-11-03
|
787b
|
43 lines
int
igchecksum (z, c)
register const char *z;
register int c;
{
register unsigned int ichk1, ichk2;
ichk1 = 0xffff;
ichk2 = 0;
do
{
register unsigned int b;
/* Rotate ichk1 left. */
if ((ichk1 & 0x8000) == 0)
ichk1 <<= 1;
else
{
ichk1 <<= 1;
++ichk1;
}
/* Add the next character to ichk1. */
b = *z++ & 0xff;
ichk1 += b;
/* Add ichk1 xor the character position in the buffer counting from
the back to ichk2. */
ichk2 += ichk1 ^ c;
/* If the character was zero, or adding it to ichk1 caused an
overflow, xor ichk2 to ichk1. */
if (b == 0 || (ichk1 & 0xffff) < b)
ichk1 ^= ichk2;
}
while (--c > 0);
return ichk1 & 0xffff;
}