code: def _calculate_crc_ccitt(data):
      
      global CRC_CCITT_TABLE
      if not CRC_CCITT_TABLE:
          crc_ccitt_table = []
          for i in range(0, 256):
              crc = 0
              c = i << 8
  
              for j in range(0, 8):
                  if (crc ^ c) & 0x8000:
                      crc = c_ushort(crc << 1).value ^ 0x1021
                  else:
                      crc = c_ushort(crc << 1).value
  
                  c = c_ushort(c << 1).value
  
              crc_ccitt_table.append(crc)
              CRC_CCITT_TABLE = crc_ccitt_table
  
      is_string = _is_string(data)
      crc_value = 0x0000  # XModem version
  
      for c in data:
          d = ord(c) if is_string else c
          tmp = ((crc_value >> 8) & 0xff) ^ d
          crc_value = ((crc_value << 8) & 0xff00) ^ CRC_CCITT_TABLE[tmp]
  
      return crc_value
docs: All CRC stuff ripped from PyCRC, GPLv3 licensed