Skip to main content

PyPI crc16

Project description

本模块主要进行数据校验:支持查表法和直接法。支持crc16常用校验法和自定义校验。详细用法可参照代码。

crc32仅仅实现了经典法。

'''
Created on 2021年1月8日

@author: Administrator
'''
from zp_pycrc import *
def test_crc32():
    datas=b'\x01\x02\x03\x04\x05'
    r=cal_crc32_classcial(datas, 0xffffffff, 0x04c11db7, True, True, 0xffffffff)
    print(hex(r))
def test_crc16():   
    datas=b'\x01\x02\x03\x04\x05'
    print(len(datas),datas)
    crc=crc16_ccitt()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_ccitt_false()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_xmodem()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_x25()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_ibm()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_usb()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_maxim()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_modbus()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_dnp()
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
        
    crc=crc16( 0,0x8005, True, True, 0)
    print(crc.__class__.__name__,"%04X"%(crc.cal(datas)))
    crc=crc16_ibm()
    print("crc16_ibm __call__",hex(crc(datas)))
    b=cal_crc16_classcial(datas, 0,0x8005, True, True, 0)
    print("cal_crc16_classcial",hex(b))
    print('*******crc ibm table*****')
    print([hex(i) for i in crc.crc_table])
if __name__ == '__main__':
    test_crc16()
    test_crc32()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zp_pycrc-0.0.2.tar.gz (3.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page