Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!CITHEX.CALTECH.EDU!carl From: carl@CITHEX.CALTECH.EDU.UUCP Newsgroups: comp.os.vms Subject: Re: VMS CHECKSUM algorithm Message-ID: <870628092732.00f@CitHex.Caltech.Edu> Date: Sun, 28-Jun-87 12:43:00 EDT Article-I.D.: CitHex.870628092732.00f Posted: Sun Jun 28 12:43:00 1987 Date-Received: Tue, 30-Jun-87 01:11:08 EDT References: <3135@eagle.ukc.ac.uk> Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 29 > Anyone know the algoritm used by the undocumented CHECKSUM command on > VAX/VMS? I'd like to be able to generate/check these on non VAX/VMS systems, > to allow some measure of checking on transferred files. I assume that you only need the algorithm for CHECKSUM/FILE, and not the stuff for CHECKSUM/IMAGE. If this is the case, then what you need to know (assuming that you've opened the file with RMS, and that your RAB is called "myrab") is: #include rab #include rms unsigned long *longbuffer; unsigned char *charbuffer; long n_longwords, n_bytes, i; checksum = 0; while ((status = SYS$GET(myrab)) != rms$_eof) { if ((status & 7) != 1) { puts("Error during read:"); exit(status); } n_longwords = myrab.rab$w_rsz/4; n_bytes = myrab.rab$w_rsz & 3; longbuffer = (unsigned long *) &(myrab.rab$l_rbf); bytebuffer = (unsigned char *) &(longbuffer[n_longwords]); for (i = 0; i < n_longwords; ++i) checksum = checksum XOR longbuffer[i]; for (i = 0; i < n_bytes; ++i) checksum = checksum + bytebuffer[i]; }