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_8rohc(self): data = NumberMask(0xF00F, 16) inputPoly = NumberMask(0x107, 8) regInit = 0xFF xorOut = 0x0 crc_func = crcmod.predefined.mkCrcFun('crc-8-rohc') ## rev crcLib = crc_func(data.toASCII()) crcProc = ModCRC() crcProc.setReversed() crcProc.setRegisterInitValue(regInit) crcProc.setXorOutValue(xorOut) crc = crcProc.calculate3(data, inputPoly) # print "crcx: {:b} {:b}".format( crcLib, crc ) self.assertEqual(crc, crcLib)
def test_crcmod_8rev_init(self): data = NumberMask(0xFF0F, 16) inputPoly = NumberMask(0x181, 8) regInit = 0x0F xorOut = 0x0 crc_func = crcmod.mkCrcFun(inputPoly.masterData(), initCrc=regInit, rev=True, xorOut=xorOut) crcLib = crc_func(data.toASCII()) crcProc = ModCRC() crcProc.setReversed() crcProc.setRegisterInitValue(regInit) crcProc.setXorOutValue(xorOut) crc = crcProc.calculate3(data, inputPoly) # print "crcx: {:b} {:b}".format( crc, crcLib ) self.assertEqual(crc, crcLib)
def test_crcmod_8darc(self): data = NumberMask(0x01, 8) inputPoly = NumberMask(0x139, 8) regInit = 0x0 xorOut = 0x0 crc_func = crcmod.predefined.mkCrcFun('crc-8-darc') crcLib = crc_func(data.toASCII()) crcProc = ModCRC() crcProc.setReversed() crcProc.setRegisterInitValue(regInit) crcProc.setXorOutValue(xorOut) revData = data.reorderedBytes() crc = crcProc.calculate3(revData, inputPoly) # print "crcx: {:b} {:b}".format( crc, crcLib ) self.assertEqual(crc, crcLib)
def test_crcmod_8rev_symm(self): data = NumberMask(0xFF, 8) inputPoly = NumberMask(0x181, 8) ## leave symmetric regInit = 0x0 xorOut = 0x0 crc_func = crcmod.mkCrcFun(inputPoly.masterData(), initCrc=regInit, rev=True, xorOut=xorOut) crcLib = crc_func(data.toASCII()) crcProc = ModCRC() crcProc.setReversed() crcProc.setRegisterInitValue(regInit) crcProc.setXorOutValue(xorOut) revData = data.reorderedBytes() revPoly = inputPoly.reversed() crc = crcProc.calculate3(revData, revPoly) # print "crcx: {:b} {:b}".format( crc, crcLib ) self.assertEqual(crc, crcLib)