A Tcl implementation of the unix sum(1) command is now part of [Tcllib] and should appear in the 1.2 release. Both the BSD and SysV algorithms are implemented although more consistent results across many platforms may be obtained using the [cksum] command. The [sum] algorithms return a 16 bit checksum of the input data calculated by summing the values of each byte of data. The BSD algorithm includes a right bit-rotation which ensures that the ''order'' of the bytes is also significant. The SysV algorithm is expressed as: s = sum of bytes r = s % 2^16 + (s % 2^32) / 2^16 cksum = (r % 2^16) + r / 2^16 or more usefully on a 32 bit architecture as: r = (s & 0xffff) + (s >> 8) cksum = (r & 0xffff) + (r >> 8) For example using the BSD algorithm: % package require sum 1.0 % crc::sum "Hello, World!" 37287 % crc::sum -file sum.tcl 16358 % crc::sum -format 0x%x -file sum.tcl 0x3fe6 The SysV algorithm is less robust - meaning that different data may give the same checksum. [cksum] is more robust still and [md5sum] is yet more so. % crc::sum -sysv "Hello, World!" 1129 % crc::sum -sysv "World, Hello!" 1129 ---- See the code at http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/tcllib/tcllib/modules/crc/sum.tcl?rev=HEAD&content-type=text/vnd.viewcvs-markup ---- [Category Package] subset [Tcllib] See also [crc] and [cksum]