def test_crcmod_32(self): data = 0x414243 dataSize = 24 inputPoly = 0x104c11db7 regInit = 0x0 xorOut = 0x00 crcSize = 32 # print "XXX {:X} {:X}".format( data, data2) # barray1 = bytearray.fromhex('{:x}'.format(data)) # barray2 = bytearray.fromhex('{:x}'.format(data2)) # crc32_func = crcmod.mkCrcFun(0x104c11db7, initCrc=regInit, xorOut=xorOut) crc32_func = crcmod.mkCrcFun(0x104c11db7, rev=False, initCrc=regInit, xorOut=xorOut) crcLib = crc32_func(intToASCII(data)) crcProc = ModCRC() crcProc.setRegisterInitValue(regInit) crcProc.setXorOutValue(xorOut) crc = crcProc.calculate2(data, dataSize, inputPoly, crcSize) # print "crc: {:X} {:X}".format( crcLib, crc ) self.assertEqual(crc, crcLib)
def test_crcmod_8_xorOut(self): data = 0xF0 dataSize = 8 inputPoly = 0x100 crcSize = 8 regInit = 0x0F xorOut = 0xF0 crc_func = crcmod.mkCrcFun(inputPoly, initCrc=regInit, rev=False, xorOut=xorOut) crcLib = crc_func(intToASCII(data)) crcProc = ModCRC() crcProc.setXorOutValue(xorOut) crcProc.setInitCRC(regInit, crcSize) crc = crcProc.calculate2(data, dataSize, inputPoly, crcSize) # print "crc: 0x{0:X}[0b{0:b}] 0x{1:X}[0b{1:b}]".format( crc, crcLib ) self.assertEqual(crc, crcLib)
def test_crcmod_8_data(self): data = 0xF0FF dataSize = 16 inputPoly = 0x181 ## leave symmetric crcSize = 8 regInit = 0x0 xorOut = 0x0 crc_func = crcmod.mkCrcFun(inputPoly, initCrc=regInit, rev=False, xorOut=xorOut) crcLib = crc_func(intToASCII(data)) crcProc = ModCRC() crcProc.setRegisterInitValue(regInit) crcProc.setXorOutValue(xorOut) crc = crcProc.calculate2(data, dataSize, inputPoly, crcSize) # print "crc: {:b} {:b}".format( crcLib, crc ) self.assertEqual(crc, crcLib)