Esempio n. 1
0
    def test_MSB_LSB(self):
        data = NumberMask(random.randint(1, 0xFF), 8)
        crcSize = 8
        crcMax = 2**crcSize - 1
        inputPoly = NumberMask(random.randint(1, crcMax), crcSize)
        regInit = random.randint(0, crcMax)
        xorOut = random.randint(0, crcMax)

        crcProc = DivisionCRC()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)
        crc = crcProc.calculateMSB(data, inputPoly)

        revData = data.reversed()
        revPoly = inputPoly.reversed()
        revRegInit = reverse_number(regInit, crcSize)
        revXorOut = reverse_number(xorOut, crcSize)

        revCrcProc = DivisionCRC()
        revCrcProc.setReversed()
        revCrcProc.setRegisterInitValue(revRegInit)
        revCrcProc.setXorOutValue(revXorOut)
        crc2 = revCrcProc.calculateLSB(revData, revPoly)

        revCrc = reverse_number(crc2, crcSize)

        #         print "values: data:{} poly:{:X} init:{:X} xorOut:{:08b} crc:{:08b} revcrc:{:08b}".format( data, inputPoly, regInit, xorOut, crc, revCrc )
        self.assertEqual(crc, revCrc)
Esempio n. 2
0
    def test_crcmod_c8d16_revB(self):
        data = NumberMask(0xE3F2, 16)
        inputPoly = NumberMask(0x1F0, 8)
        regInit = 0x0
        xorOut = 0x0
        reverse = True

        revInputPoly = inputPoly.reversed()
        revData = data.reorderedBytes()

        crc_func = crcmod.mkCrcFun(revInputPoly.masterData(),
                                   rev=reverse,
                                   initCrc=regInit,
                                   xorOut=xorOut)
        crcLib = crc_func(revData.toASCII())
        #         print "crc: {:X} {:X}".format( crc, crc2 )

        crcProc = DivisionCRC()
        crcProc.setReversed(reverse)
        crcProc.setXorOutValue(xorOut)
        crcProc.setRegisterInitValue(regInit)
        #         crcProc.setInitCRC( regInit )

        crc = crcProc.calculate3(data, inputPoly)

        #         print "values: {} poly:{:X} init:{:X} xorOut:{:08b} rev:{} crc:{:08b} crcmod:{:08b} crcxor:{:08b}".format( data, inputPoly, regInit, xorOut, reverse, crc, crcLib, crc^crcLib )
        self.assertEqual(crc, crcLib)
Esempio n. 3
0
    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)