我在python中进行crc16-x25计算有什么问题?

问题描述 投票:0回答:1

我在 python 3 中有这段代码来计算 CRC16-X25:

import crcmod


# CRC function using the CRC-16-CCITT standard
crc16 = crcmod.mkCrcFun(0x11021, initCrc=0xFFFF, xorOut=0xFFFF, rev=True)

def calculate_crc(data):
    return crc16(data)

hex_data = '010e00180510100b1b020100000100ff'
    
# Convert the hex string to bytes
binary_data = bytes.fromhex(hex_data)

# Calculate the CRC
crc_value = calculate_crc(binary_data)

# Print the CRC value in hexadecimal format
print(f'CRC value: {crc_value:04X}')

我不确定 rev 应该是 True 还是 False,所以无论如何我都尝试了。

但无论如何我都无法得到预期的答案

0xAF47

但是当我用这个在线工具计算计算crc16-x25

CRC-16/X-25
中它确实给出了
0xAF47

enter image description here

那么,我的Python代码有什么问题吗?

顺便说一句:

crcmod.predefined.Crc('x-25')
DO 给出了预期的结果。
mkCrcFun(0x11021, initCrc=0xFFFF, xorOut=0xFFFF, rev=True)
有什么问题吗?

python crc crc16
1个回答
0
投票

使用

crcmod.mkCrcFun(0x11021, initCrc=0, xorOut=0xFFFF, rev=True)

© www.soinside.com 2019 - 2024. All rights reserved.