def test_crcmod_8_random(self): data = NumberMask(random.randint(1, 0xFFFFFFFFFFFFFFFF), 64) crcSize = 8 crcMax = 2**crcSize - 1 inputPoly = NumberMask((0x1 << crcSize) | random.randint(1, crcMax), crcSize) # regInit = random.randint(0, crcMax) # xorOut = random.randint(0, crcMax) regInit = 0x0 xorOut = 0x0 reverse = bool(random.randint(0, 1)) crc_func = crcmod.mkCrcFun(inputPoly.masterData(), rev=reverse, initCrc=regInit, xorOut=xorOut) crcLib = crc_func(data.toASCII()) # print "crc: {:X} {:X}".format( crc, crc2 ) crcProc = ModCRC() crcProc.setReversed(reverse) crcProc.setXorOutValue(xorOut) crcProc.setInitCRC(regInit, crcSize) crc = crcProc.calculate3(data, inputPoly) 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)