sum(n)
๐ sum(n) โ Cyclic Redundancy Checks ๐
okay bestie, buckle up, we're doing the sum page and it's actually so cute once you get it. this is sum(n), the Tcl manual page, and by the end you're gonna be checksumming like it's nothing. periodt. โจ
๐ธ NAME ๐ธ
sum โ Calculate a sum(1) compatible checksum ๐
๐ SYNOPSIS ๐
package require Tcl 8.5 9
package require sum ?1.1.3?
::crc::sum ?-bsd | -sysv? ?-format fmt? ?-chunksize size? [ -filename
file | -channel chan | string ]
โจ DESCRIPTION โจ
so this package is a Tcl-only implementation of the sum(1) command โ no cap, pure Tcl, no sneaky C hiding in there. it calculates a 16 bit checksum value from whatever input data you hand it. ๐งฎ
by default it uses the BSD sum algorithm, but the SysV algorithm is also available if that's your vibe. both are in the building, you just gotta pick. ๐ซถ
๐ COMMANDS ๐
::crc::sum ?-bsd | -sysv? ?-format fmt? ?-chunksize size? [ -filename file | -channel chan | string ]โ okay so this command takes string data, or a file name, or a channel, and it hands you back a checksum value calculated with thesum(1)algorithm. the result gets formatted using theformat(n)specifier you provide โ or, if you don't provide one, it's just an unsigned integer (%u) by default. the way it just... formats for you? iconic. ๐
๐ OPTIONS ๐
-sysvโ the SysV algorithm is, ngl, fairly naive. it just sums up all the byte values and tosses any overflow in the bin. the lowest 16 bits come back as your checksum. heads up though: input with the same content but a different ordering gives you the same result. so if order matters to you... it does not matter to SysV. ๐-bsdโ this one is similar to the SysV version but it adds a bit rotation step, which means it actually has a dependency on the order of the data values. so yes, order matters here. main character behavior tbh. ๐-filenamename โ gives you a checksum for the file contents instead of for the parameter data. ๐-channelchan โ gives you a checksum for the contents of the channel you specify. the channel must be open for reading and should be configured for binary translation. and fyi: the channel will not be closed on completion, so don't expect it to dip on you. ๐-chunksizesize โ sets the block size used when reading data from either files or channels. this value defaults to4096. ๐ฆ-formatstring โ returns the checksum using an alternative format template. glow-up for your output. โจ
๐ฆ EXAMPLES ๐ฆ
% crc::sum "Hello, World!"
37287
% crc::sum -format 0x%X "Hello, World!"
0x91A7
% crc::sum -file sum.tcl
13392
like?? look at that. 37287, 0x91A7, 13392. she ate. ๐ฅ
๐ธ AUTHORS ๐ธ
Pat Thoyts โ the legend themselves. ๐
๐ญ BUGS, IDEAS, FEEDBACK ๐ญ
okay so real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. it's giving honest. please report such in the category crc of the Tcllib Trackers:
http://core.tcl.tk/tcllib/reportlist
and please also report any ideas for enhancements you may have for either the package and/or the documentation. we wanna hear it, fr fr. ๐ซถ
when proposing code changes, please provide unified diffs, i.e. the output of diff -u. ๐
also note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk. ๐
๐ SEE ALSO ๐
โญ KEYWORDS โญ
checksum, cksum, crc, crc32, cyclic redundancy check, data integrity, security, sum ๐
๐ CATEGORY ๐
Hashes, checksums, and encryption ๐
๐ COPYRIGHT ๐
Copyright (c) 2002, Pat Thoyts <patthoyts@users.sourceforge.net>
and that's the whole page, bestie!! this one came from tcllib, version 1.1.3, and it's the sum(n) page โ go forth and checksum responsibly. mwah, ily, bye!! ๐โจ๐๐ฆ๐ธ
๐ฆ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 ยท TCL
- fedora 44: tcllib 2.0-4.fc44 ยท TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2002, Pat Thoyts <patthoyts@users\&.sourceforge\&.net>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms