1crc16(n)                   Cyclic Redundancy Checks                   crc16(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       crc16 - Perform a 16bit Cyclic Redundancy Check
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require crc16  ?1.1.3?
14
15       ::crc::crc16  ?-format format? ?-seed value? ?-implementation procname?
16       -- message
17
18       ::crc::crc16 ?-format format? ?-seed value? ?-implementation  procname?
19       -filename file
20
21       ::crc::crc-ccitt  ?-format format? ?-seed value? ?-implementation proc‐
22       name? -- message
23
24       ::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation  proc‐
25       name? -filename file
26
27       ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname?
28       -- message
29
30       ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname?
31       -filename file
32
33______________________________________________________________________________
34

DESCRIPTION

36       This  package  provides a Tcl-only implementation of the CRC algorithms
37       based   upon   information    provided    at    http://www.microconsul
38       tants.com/tips/crc/crc.txt There are a number of permutations available
39       for calculating CRC checksums and this package can handle all of  them.
40       Defaults are set up for the most common cases.
41

COMMANDS

43       ::crc::crc16  ?-format format? ?-seed value? ?-implementation procname?
44       -- message
45
46       ::crc::crc16 ?-format format? ?-seed value? ?-implementation  procname?
47       -filename file
48
49       ::crc::crc-ccitt  ?-format format? ?-seed value? ?-implementation proc‐
50       name? -- message
51
52       ::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation  proc‐
53       name? -filename file
54
55       ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname?
56       -- message
57
58       ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname?
59       -filename file
60              The  command takes either string data or a file name and returns
61              a checksum value calculated using the CRC algorithm. The command
62              used  sets up the CRC polynomial, initial value and bit ordering
63              for the desired standard checksum  calculation.  The  result  is
64              formatted  using  the  format(n)  specifier  provided  or  as an
65              unsigned integer (%u) by default.
66
67              A number of common polynomials are in use with the CRC algorithm
68              and  the  most commonly used of these are included in this pack‐
69              age. For convenience each of these has a command  alias  in  the
70              crc namespace.
71
72              It is possible to implement the CRC-32 checksum using this crc16
73              package as the implementation is sufficiently generic to  extend
74              to  32 bit checksums. As an example this has been done already -
75              however this is not the fastest method to implement  this  algo‐
76              rithm in Tcl and a separate crc32 package is available.
77

OPTIONS

79       -filename name
80              Return a checksum for the file contents instead of for parameter
81              data.
82
83       -format string
84              Return the checksum using an alternative format template.
85
86       -seed value
87              Select an alternative seed value for the  CRC  calculation.  The
88              default  is 0 for the CRC16 calculation and 0xFFFF for the CCITT
89              version.  This can be useful for calculating the  CRC  for  data
90              structures  without  first converting the whole structure into a
91              string. The CRC of the previous member can be used as  the  seed
92              for  calculating the CRC of the next member. It is also used for
93              accumulating a checksum from fragments of a  large  message  (or
94              file)
95
96       -implementation procname
97              This hook is provided to allow users to provide their own imple‐
98              mentation (perhaps a C compiled extension). The procedure  spec‐
99              fied  is called with two parameters. The first is the data to be
100              checksummed and the second is the  seed  value.  An  integer  is
101              expected as the result.
102
103              The  package provides some implementations of standard CRC poly‐
104              nomials for the XMODEM, CCITT and the usual CRC-16 checksum. For
105              convenience,  additional  commands  have been provided that make
106              use of these implementations.
107
108       --     Terminate option processing. Please note that using  the  option
109              termination  flag is important when processing data from parame‐
110              ters. If the binary data looks like one  of  the  options  given
111              above  then the data will be read as an option if this marker is
112              not included.  Always use the -- option termination flag  before
113              giving the data argument.
114

EXAMPLES

116              % crc::crc16 -- "Hello, World!"
117              64077
118
119
120              % crc::crc-ccitt -- "Hello, World!"
121              26586
122
123
124              % crc::crc16 -format 0x%X -- "Hello, World!"
125              0xFA4D
126
127
128              % crc::crc16 -file crc16.tcl
129              51675
130
131

AUTHORS

133       Pat Thoyts
134

BUGS, IDEAS, FEEDBACK

136       This  document,  and the package it describes, will undoubtedly contain
137       bugs and other problems.  Please report such in the category crc of the
138       Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].   Please also
139       report any ideas for enhancements  you  may  have  for  either  package
140       and/or documentation.
141
142       When proposing code changes, please provide unified diffs, i.e the out‐
143       put of diff -u.
144
145       Note further that  attachments  are  strongly  preferred  over  inlined
146       patches.  Attachments  can  be  made  by  going to the Edit form of the
147       ticket immediately after its creation, and  then  using  the  left-most
148       button in the secondary navigation bar.
149

SEE ALSO

151       cksum(n), crc32(n), sum(n)
152

KEYWORDS

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

CATEGORY

158       Hashes, checksums, and encryption
159
161       Copyright (c) 2002, 2017, Pat Thoyts
162
163
164
165
166tcllib                               1.1.3                            crc16(n)
Impressum