%$Header$ \chapter[\ccchzeroshorttitle{}]{\ccchzerolongtitle{}} \label{ccch0} \beginchapterquote{``\ldots{} Beauty is the first test: there is no permanent place in the world for ugly mathematics.''} {G.H. Hardy \cite{bibref:b:mathematiciansapology:1940}, p.85} \section{Introduction} %Section Tag: INT \section{crc32} \begin{tclcommandname}{crc32}% generates the CRC-32 of a file or string. This CRC can be reliably used to obtain digital signatures of files or data. \end{tclcommandname} \begin{tclcommandsynopsis} \tclcommandsynopsisline{crc32}{filename} \tclcommandsynopsisline{crc32}{-string binarystringval} \tclcommandsynopsisline{crc32}{-initialstate} \tclcommandsynopsisline{crc32}{-advancestate state filename} \tclcommandsynopsisline{crc32}{-advancestate -string state binarystringval} \tclcommandsynopsisline{crc32}{-crcfromstate state} \end{tclcommandsynopsis} \begin{tclcommanddescription} The \emph{crc32} command forms the CRC-32 of the binary contents of a file or of the binary contents of a string. The CRC-32 is useful as a digital signature, and can be used with unity probability to determine that two files are different, or with a probability of about $1-2^{-32}$ to determine that two files are almost certainly identical. In the invocations below, the CRC-32 is always returned as a 10-character ASCII string of the form \emph{``0xDDDDDDDD''}, where \emph{``DDDDDDDD''} is the hexadecimal representation of the 32-bit CRC-32, and \emph{``0x''} is a constant 2-character prefix which is included for aesthetics. It is guaranteed that: \begin{itemize} \item The string returned will be exclusive ASCII. \item The string will have a length of exactly 10 characters. \item The first two characters of the string will be \emph{``0x''}. \item Any letters in the hexadecimal representation will be upper-case. \end{itemize} \begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{filename}} Returns the CRC-32 of \emph{filename}, treated as an ordered collection of bytes (i.e. newline characters and file termination characters are not treated---the file is treated as a binary file). \emph{filename} must be specified in the form accepted by the Tcl internals (forward slashes only). \end{tclcommandinternaldescription} \begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{-string binarystringval}} Returns the CRC-32 of \emph{binarystringval}, treated as an ordered collection of bytes (i.e. newline characters and string termination characters are not honored---the string is treated as a binary string).\footnote{For an ASCII string, the \emph{crc32} extension will behave as expected, and will process all characters up to but not including the zero terminator. However, the \emph{crc32} extension will also correctly process non-ASCII strings.} \end{tclcommandinternaldescription} \begin{tclcommandinternaldescription}{\tclcommanddescsynopsisline{crc32}{-initialstate}% \tclcommanddescsynopsisline{crc32}{-advancestate state filename}% \tclcommanddescsynopsisline{crc32}{-advancestate -string state filename}% \tclcommanddescsynopsisline{crc32}{-crcfromstate state}% } The four forms above are designed to allow ``running CRCs'' to be calculated; in which the CRC is calculated piecemeal. These forms allow the caller to retain the internal state vector of the CRC calculation algorithm. The first form, \emph{crc32 -initialstate}, returns an ASCII representation of the correct initial state vector of the CRC-32 state machine. The client is required to obtain this initial state before beginning a piecemeal CRC calculation. Although the returned string is a constant (it will always be the same), representational details may change in future versions of the \emph{crc32} extension, and so a caller should never make assumptions about what this invocation will return, as these assumptions may render a script incompatible with future versions of \emph{crc32}. The second and third forms, \emph{crc32 -advancestate state filename} and \emph{crc32 -advancestate -string state filename}, apply a file or a binary string to \emph{state} to produce a new \emph{state}, which is returned. This new \emph{state} must be retained by the caller and used in subsequent calls. The final form, \emph{crc32 -crcfromstate state}, maps from the state vector to the calculated CRC, and will return a 10-character ASCII string as described above. \end{tclcommandinternaldescription} \end{tclcommanddescription} \begin{tclcommandusagenotes} The ``piecemeal'' forms are as efficient as the file and string forms---there is no difference in the internal algorithms. The primary cost of the piecemeal forms is in importing and exporting the algorithm state vector to/from an ASCII string. Thus, the piecemeal forms become less efficient when small files or strings are processed, as there are more exports and imports of the state vector. When using the piecemeal forms, processing the data in larger chunks will give better performance. \end{tclcommandusagenotes} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \noindent\begin{figure}[!b] \noindent\rule[-0.25in]{\textwidth}{1pt} \begin{tiny} \begin{verbatim} $HeadURL$ $Revision$ $Date$ $Author$ \end{verbatim} \end{tiny} \noindent\rule[0.25in]{\textwidth}{1pt} \end{figure} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %End of file C_CCH0.TEX