예제 #1
0
    def add(self, byte):
        """Add a new byte to the CRC engine. 'byte'
        should be a python character. E.g: c.add('x')

        """
        # CRC-16 polynomial
        poly_s = byte ^ (self.state >> 8)
        poly_t = poly_s ^ (poly_s >> 4)
        result = s16l(self.state, 8) ^ poly_t ^ s16l(poly_t, 5) ^ s16l(poly_t, 12)
        self.state = result
예제 #2
0
파일: crc16.py 프로젝트: GaloisInc/echronos
    def add(self, byte):
        """Add a new byte to the CRC engine. 'byte'
        should be a python character. E.g: c.add('x')

        """
        # CRC-16 polynomial
        s = byte ^ (self.state >> 8)
        t = s ^ (s >> 4)
        r = s16l(self.state, 8) ^ t ^ s16l(t, 5) ^ s16l(t, 12)
        self.state = r
예제 #3
0
def check_s16l(value, n, expected):
    assert s16l(value, n) == expected
예제 #4
0
 def test_s16l_ffff(self):
     for num, expected in [(1, 0xfffe), (8, 0xff00), (15, 0x8000), (16, 0)]:
         self.assertEqual(s16l(0xffff, num), expected)
예제 #5
0
 def test_s16l_zero(self):
     for num in range(16):
         self.assertEqual(s16l(0, num), 0)