// C# port of the ccitt.c/ccitt.h files in this directory. // Original files generated by pycrc v0.9, https://pycrc.org namespace Checksums { public static class Ccitt { /** * Calculate the initial crc value. * * \return The initial crc value. *****************************************************************************/ public static ushort Init() { return 0xffff; } /** * Update the crc value with new data. * * \param crc The current crc value. * \param data Pointer to a buffer of \a data_len bytes. * \param data_len Number of bytes in the \a data buffer. * \return The updated crc value. *****************************************************************************/ public static ushort Update( ushort crc, byte[] data, long data_len ) { uint i; bool bit; byte c; for ( long idx = 0; idx < data_len; ++idx ) { c = data[idx]; for ( i = 0x80; i > 0; i >>= 1 ) { bit = ( crc & 0x8000 ) != 0; if ( ( c & i ) != 0 ) { bit = !bit; } crc <<= 1; if ( bit ) { crc ^= 0x1021; } } crc &= 0xffff; } return (ushort)( crc & 0xffff ); } /** * Calculate the final crc value. * * \param crc The current crc value. * \return The final crc value. *****************************************************************************/ public static ushort Finalize( ushort crc ) { return (ushort)( crc ^ 0x0000 ); } } }