def crc_16_ibm(self, data):
        hex_data = data.decode("hex")
        byte_list = map(ord, hex_data)
        num1 = 0
        for i in xrange(0, len(byte_list)):
            num2 = byte_list[i]
            if i == 2 or i == 3:
                num2 = 0
            num1 ^= num2
            for j in xrange(0, 8):
                if num1 & 1 > 0:
                    num1 = (num1 >> 1) ^ 40961
                else:
                    num1 >>= 1
        code = num1 & 65535  # integer returned from CRC function

        # change hex string to list to support assignment
        data_list = list(data)

        # switch order to little endian and return unsigned short, then
        # replace characters in list with the CRC values
        data_list[4:8] = struct.pack('<H', code).encode('hex')

        return "".join(data_list)
Returns hex string with CRC values added to positions 4 through 8.
dataset/ETHPy150Open pawl/Chinese-RFID-Access-Control-Library/rfid.py/RFIDClient.crc_16_ibm