File:  [CSRG BSD Unix] / 40BSD / cmd / uucp / chksum.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:53 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD40
BSD 4.0

main()
{
	int i, j;
	char buf[300];

	for (i = 0; i < 300; i++)
		buf[i] = i;
	printf("%o\n", chksum(buf, 300));
}

chksum(s,n)
register char *s;
register n;
{
	register short sum;
	register unsigned t;
	register x;

	sum = -1;
	x = 0;

	do {
		if (sum<0) {
			sum <<= 1;
			sum++;
		} else
			sum <<= 1;
		t = sum;
		sum += (unsigned)*s++;
		x += sum^n;
		if ((unsigned)sum <= t) {
			sum ^= x;
		}
	} while (--n > 0);

	return(sum);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.