Skip to main content

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

crc32仅仅实现了经典法。

import unittest
from zp_pycrc import *
class crc_test(unittest.TestCase):
    def test_crc16(self):
        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])
        
    def test_crc32(self):
        datas=b'\x01\x02\x03\x04\x05'
        r=cal_crc32_classcial(datas, 0xffffffff, 0x04c11db7, True, True, 0xffffffff)
        print(hex(r))

if __name__ == '__main__':
    unittest.main()

Release files for zp-pycrc 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zp-pycrc 0.0.4
File Size Uploaded
zp_pycrc-0.0.4.tar.gz 3.6 kB Details

Release files / zp_pycrc-0.0.4.tar.gz

Download URL zp_pycrc-0.0.4.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a0fe10419abe9c18faeafd72c58ae9e894e6ba98a77571aa5bbf22ec65c97d54
BLAKE2b-256 checksum
How to use checksums
cda7b47d5f140c715866dedba3523ffb3bb0049a9452e8d132852c48ea361fb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page