Example #1
0
    def test_calculateCRC_8_b(self):
        dataSize = 56
        inputPoly = 0x11D
        crcSize = 8
        regInit = 0x00
        xorOut = 0x8F

        crc = ModCRC().calculateCRC(0x0D00C0F0FFFFFF,
                                    dataSize,
                                    inputPoly,
                                    crcSize,
                                    init=regInit,
                                    xorout=xorOut)
        self.assertEqual(crc, 0x90)

        crc = ModCRC().calculateCRC(0x0000C0F0FFFFFF,
                                    dataSize,
                                    inputPoly,
                                    crcSize,
                                    init=regInit,
                                    xorout=xorOut)
        self.assertEqual(crc, 0x76)

        crc = ModCRC().calculateCRC(0x0E00C0F0FFFFFF,
                                    dataSize,
                                    inputPoly,
                                    crcSize,
                                    init=regInit,
                                    xorout=xorOut)
        self.assertEqual(crc, 0x77)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    def test_calculateCRC_8_a(self):
        ## http://www.sunshine2k.de/coding/javascript/crc/crc_js.html
        dataSize = 4 * 8
        inputPoly = 0x1D
        crcSize = 8

        crc = ModCRC().calculateCRC(0x31323334,
                                    dataSize,
                                    inputPoly,
                                    crcSize,
                                    reverse=False)
        self.assertEqual(crc, 0xF2)

        crc = ModCRC().calculateCRC(0x31323334,
                                    dataSize,
                                    inputPoly,
                                    crcSize,
                                    reverse=True)
        self.assertEqual(crc, 0x43)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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)
Example #8
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)
Example #9
0
    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)
Example #10
0
    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)