from pm3py.core.protocol import crc16_a, crc15, crc15_bytes def test_crc16_a_empty(): assert crc16_a(b"") == 0x6363 # init 0xC6C6 reflected = 0x6363 def test_crc16_a_known_vector(): # Verified against C implementation: compute_crc(CRC_14443_A, ...) # "123456789" is the standard CRC check string data = b"123456789" assert crc16_a(data) == 0xBF05 def test_crc16_a_ping_preamble(): # A CMD_PING preamble: magic=0x61334d50, length|ng=0x8020, cmd=0x0109 preamble = bytes.fromhex("504d3361208001090102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") crc = crc16_a(preamble) assert isinstance(crc, int) assert 0 <= crc <= 0xFFFF def test_crc15_known_vector(): # ISO15693 / NFC Type 5 CRC == CRC-16/X-25; standard check string -> 0x906E assert crc15(b"123456789") == 0x906E def test_crc15_residue(): # Appending crc15 (LSB-first) then re-running the raw X-25 loop over the full # frame yields the X-25 residue 0xF0B8 — the property firmware CheckCrc15 uses. data = bytes([0x26, 0x01, 0x00]) frame = data + crc15_bytes(data) crc = 0xFFFF for byte in frame: crc ^= byte for _ in range(8): crc = (crc >> 1) ^ 0x8408 if (crc & 1) else (crc >> 1) assert crc == 0xF0B8