crc16(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

🌸 crc16(n) β€” the manual page, but make it make sense 🌸

okay so bestie, this is crc16(n) from the Cyclic Redundancy Checks corner of the manual. It's long, so we're doing it in parts β€” this is part 1, and I'm not skimping on a single flag, periodt. πŸ’…


✨ NAME ✨

crc16 β€” Perform a 16bit Cyclic Redundancy Check


πŸ¦‹ SYNOPSIS πŸ¦‹

package require Tcl 8.5 9

package require crc16 ?1.1.5?

::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::umts ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::umts ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::cms ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::cms ?-format format? ?-seed value? ?-implementation procname? -filename file

πŸ’– DESCRIPTION πŸ’–

So this package is a Tcl-only implementation of the CRC algorithms, built on the info from http://www.microconsultants.com/tips/crc/crc.txt β€” credit where it's due, iykyk.

There are a lot of permutations for calculating CRC checksums, and this package handles all of them. The defaults are already set up for the most common cases, so you don't have to think about it unless you want to. 🫢


πŸ‘‘ COMMANDS πŸ‘‘

::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::kermit ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::modbus ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::mcrf4xx ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::genibus ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-x25 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-sdlc ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::crc-usb ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::buypass ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::umts ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::umts ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::gsm ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::unknown2 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::maxim ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::unknown3 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::unknown4 ?-format format? ?-seed value? ?-implementation procname? -filename file

::crc::cms ?-format format? ?-seed value? ?-implementation procname? -- message

::crc::cms ?-format format? ?-seed value? ?-implementation procname? -filename file

So like, the way this works: the command takes either string data or a file name, and it hands you back a checksum value computed with the CRC algorithm. πŸ’«

The command you pick is what sets up the CRC polynomial, the initial value and the bit ordering for whichever standard checksum you're trying to calculate. And the result gets formatted using the format(n) specifier you gave it β€” or, if you gave none, as an unsigned integer (%u) by default.

There are a bunch of common polynomials in use with CRC, and the most commonly used ones are already in this package. And because the devs love us, each one has a command alias in the crc namespace. convenient? iconic. πŸ’…

Also, real talk: you can implement the CRC-32 checksum using this crc16 package, because the implementation is generic enough to stretch to 32 bit checksums. That's literally already been done as an example. But β€” and this is the important part β€” it is not the fastest way to do this algorithm in Tcl, and there's a separate crc32 package available if speed is your thing. no cap.


πŸŽ€ OPTIONS πŸŽ€

  • -filename name β€” give me a checksum for the file contents instead of for the parameter data. file girlies rise πŸ“
  • -format string β€” hand back the checksum using an alternative format template.
  • -seed value β€” pick an alternative seed value for the CRC calculation. The default is 0 for the CRC16 calculation and 0xFFFF for the CCITT version. This is lowkey so useful for calculating the CRC of data structures without first converting the whole entire structure into a string β€” you can take the CRC of the previous member and use it as the seed for the next member's CRC. It's also what you use for accumulating a checksum out of fragments of a big message (or file). 🧚
  • -implementation procname β€” this hook exists so you can bring your own implementation (maybe a C compiled extension, main character energy). The procedure you specify gets called with two parameters: the first is the data to be checksummed, the second is the seed value. An integer is expected back as the result. The package already ships some implementations of standard CRC polynomials for XMODEM, CCITT and the usual CRC-16 checksum. And for convenience, extra commands have been provided that use these implementations. 🫢
  • -- β€” terminate option processing.
⚠️ okay this one matters SO much: using the option termination flag is important when you're processing data from parameters. If the binary data happens to look like one of the options above, then that data will be read as an option if this marker isn't there. Always use the -- option termination flag before giving the data argument. always. πŸ’€

🌈 EXAMPLES 🌈

% crc::crc16 -- "Hello, World!"
64077

% crc::crc-ccitt -- "Hello, World!"
26586

% crc::crc16 -format 0x%X -- "Hello, World!"
0xFA4D

% crc::crc16 -file crc16.tcl
51675

πŸ’œ AUTHORS πŸ’œ

Pat Thoyts


okay bestie that's part 1, there's more coming so don't go anywhere πŸ‘€

πŸ› BUGS, IDEAS, FEEDBACK πŸ’€

okay bestie, real talk: this doc and the whole package it describes? undoubtedly gonna have bugs and other problems. that's just how software is, no cap. not a vibe, but it's the truth. πŸ™ˆ

so if you find something busted, pls report it in the category crc of the Tcllib Trackers:

http://core.tcl.tk/tcllib/reportlist

and hey β€” got ideas for enhancements for the package and/or the documentation? report those too!! we wanna hear them, fr fr. your glow-up suggestions are welcome. ✨

when you're proposing code changes, pls hand over unified diffs, i.e. the output of diff -u. that's the format, periodt.

πŸ’‘ also!! attachments are strongly preferred over inlined patches. like, hugely. to attach one, go to the Edit form of the ticket immediately after its creation, then use the left-most button in the secondary navigation bar. that's the whole trick, iykyk. πŸŽ€

πŸ‘€ SEE ALSO 🌈

go check these out too, they're the whole friend group:


πŸ”‘ KEYWORDS πŸ¦‹

so if you're searching for this page later, these are the lil tags that'll find it:

checksum, cksum, crc, crc16, crc32, cyclic redundancy check, data integrity, security


πŸ“š CATEGORY πŸ’…

it lives under: Hashes, checksums, and encryption

iconic little neighborhood tbh. πŸ‘‘


Copyright (c) 2002, 2017, Pat Thoyts


and that's a wrap on the whole page bestie!! 🫢 this lil masterpiece is from tcllib, version 1.1.5, filed under crc16(n) β€” and the date stamp at the bottom of the page is part of the footer too, right there next to the version. go checksum something and slay. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from