1 CHKSM
CHKSM [-v] input_file [output_file]

NB: To avoid a conflict with a VAX VMS system program named CHECKSUM,
this program has been renamed CHKSM on that operating system.  The
documentation below reflects the name change.

CHKSM computes a 16-bit cyclic redundancy checksum (CRC) for a file,
as well as counts of the words, lines and characters.  With no filenames
on the command line, SYS$INPUT and SYS$OUTPUT are assumed.  With one
filename, input is from that file, with output to SYS$OUTPUT.  With two
filenames, input is from the first, and output to the second.

If the checksum has previously been installed in the input file, and the
input file has not been corrupted since then, the output file will be
identical to the input file.

With the -v option, an input file is expected.  Unlike the Unix version,
the input file must come from the command line and may NOT come from
SYS$INPUT.  CHKSM will then verify whether the checksum embedded in
the file is correct or not.  A zero status code is returned for a
correct checksum, and a non-zero one otherwise.  In either case, an
informative message is printed to SYS$OUTPUT.
2 Description
CHKSM will search for the first line of its input which contains the
word checksum in lowercase and no other alphabetic characters.  We refer
to this line as the ``critical line'' of the file.  If the critical line
contains no quotation marks, then the output file created is a copy of
the input file, except that the critical line is replaced by a line
where the word checksum is replaced by the string:
                      checksum = "xxxxx lc wc cc"
Here, lc is the number of lines in the output file, written in decimal.
Similarly, wc is the word count of the output file, and cc is the
character count when the end of line character is taken to be the single
character ASCII newline (octal 012).

For many text files, it is possible to hide the ``critical line'' in a
comment near the beginning of the file.

It is difficult to arrange that a file contains its own checksum.
Instead, the field xxxxx contains the checksum, written in decimal in a
five-digit field (with possible leading 0's) of the file obtained from
the output file by replacing the field containing the checksum by the
string ZZZZZ.

If the critical line already contains after the word ``checksum''
precisely two quotation marks, and the first is the last character of
the four-character string:
         `` = "'' (i.e.  <blank><equals><blank><quotation mark>)
then the material between the two quotation marks will be deleted and
replaced by a checksum and three counts as described above.

While the counts of words, characters, and lines could be obtained by
the UNIX wc(1) utility, that information is still not sufficient to
detect character substitutions, or transpositions of characters, lines,
and words.  The CRC-16 checksum remedies that, since the resulting
checksum depends on the order and value of every single byte in the
file.

CHKSM is intended to support the reliable exchange of text files
between different computers, even ones with different operating systems.
Thus, the newline character sequence that terminates each line is
treated as if it were an ASCII newline (linefeed) character, even though
it may be a carriage return, a carriage return and a line feed, or
simply an end-of-record condition in the file, depending on the
operating system and file type.  The file checksum is therefore
independent of the particular representation of end-of-line.

Although UNIX systems have a file checksum utility, sum(1), the result
it produces differs between UNIX variants, and in any event, it is
neither publicly available for porting to other systems, nor independent
of the end-of-line representation.  CHKSM is freely available.
2 Examples
Creating the checksum:
  CHKSM <MYFILE.TEXT >MYFILE.CHECKED
  CHKSM MYFILE.TEXT >MYFILE.CHECKED
  CHKSM MYFILE.TEXT MYFILE.CHECKED
[The angle bracket forms for I/O redirection are for use on the UNIX
operating system.]
Each of these above examples take the file MYFILE.TEXT, computes the
CHKSM, and produces the new file MYFILE.CHECKED.

Verifying an existing checksum:
  CHKSM -v < MYFILE.CHECKED
  CHKSM -v MYFILE.CHECKED
Each of these above are used to verify the file MYFILE.CHECKED.
3 Creating
Creating the checksum:
  CHKSM <MYFILE.TEXT >MYFILE.CHECKED
  CHKSM MYFILE.TEXT >MYFILE.CHECKED
  CHKSM MYFILE.TEXT MYFILE.CHECKED
Each of these above examples take the file MYFILE.TEXT, computes the
CHKSM, and produces the new file MYFILE.CHECKED, which includes the
appropriate checksum result.  It is assumed that the file MYFILE.TEXT
includes the critical line in it with only the text:
  checksum
on it with no additional alphabetic characters.  Alternately, the
critical line may be formatted as:
  checksum = "anything (or nothing) included between two quote marks"
then the material between the two quotation marks will be deleted and
replaced by a checksum and three counts as described above.

If the critical line is missing or is not properly included (i.e., there
are additional alphabetic characters on it), the user will be prompted
with the message:
  The input file did not have the correct format.
  It should contain a line which has the word "checksum"
  and no other alphabetic characters.
3 Verifying
Verifying an existing checksum:
  CHKSM -v < MYFILE.CHECKED
  CHKSM -v MYFILE.CHECKED
Each of these above are used to verify the file MYFILE.CHECKED.

If MYFILE.CHECKED passes the CHKSM test, the message:
  The checksum verification of the input file was successful.
will appear.

If MYFILE.CHECKED fails the CHKSM test, the message:
  The checksum verification of the input file did not succeed.
will appear.

If MYFILE.CHECKED does not contain a critical line or contains a corrupt
critical line, the message:
  The input file did not have the correct format.
will appear.
2 Author
Original Unix version:
     Robert M. Solovay
     Department of Mathematics
     University of California
     Berkeley, CA, USA
     Tel: (415) 642-2252
     Internet: solovay@math.berkeley.edu

     Sun Release 4.1        Last change: 19 June 1992

VMS port of Unix version:
     Nelson H.F. Beebe
     Center for Scientific Computing
     Department of Mathematics
     220 South Physics Building
     University of Utah
     Salt Lake City, UT 84112
     USA
     Tel: (801) 581-5254
     FAX: (801) 581-4148
     Internet: beebe@math.utah.edu

     Last change: 26 June 1992
