Skip to main content

Extensive CRC

Project description

https://img.shields.io/pypi/v/CRCx.svg https://img.shields.io/pypi/l/CRCx https://img.shields.io/pypi/pyversions/CRCx.svg

CRCx

Extensive Cyclic Redundancy Check

Work in progress…

Examples

import crc_rc3 as crc
import crc_rc3.catalog
import crc_rc3.engines.generic
import crc_rc3.engines.tableized
import crc_rc3.tables
import zlib


data = b"123456789"
data_a = b"12345"
data_b = b"6789"
check = 0xcbf43926  # crc from crc32 algorithm for the str '123456789


"""
simple usage
        select cataloged algorithm
        parse your input data
"""
calc = crc.create(crc.catalog.crc_32())
hash_a = calc.calc(data)


"""
calculate from multiple strings of input
        via instantiate object from the calculator class
"""
calc = crc.create(crc.catalog.crc_32())
inst = calc()
inst.process(data_a)  # process, update
hash_b = inst.final()  # you can check the result halfway through the calculation
inst.process(data_b)
hash_c = inst.final()  # result, final


# todo check if is big endian
"""
if you need the hash in bytes
        big endian
"""
# hash_d = calc.calc_bytes(data)
# or
# hash_e = inst.final_bytes()


"""
create the crc table manually
"""
# table for crc32
table = crc.tables.new_lsbf(0x04c11db7, 32)
# repr it so you can put in your own code
print(crc.tables.table_repr(32, 80)(table))


"""
define your own parameters
        option to select engine algorithm
"""
# params for crc32
params = crc.new(
        # required
        width=32,
        poly=0x04c11db7,
        init=0xffffffff,
        xorout=0xffffffff,
        refin=True,
        refout=True,
        # optional
        name="crc32",
        aliases=("alias_1", "alias_2"),
        desc="description",
        table=table,  # you can manually insert table here to avoid it being
        #  calculated automatically every time your program starts
)
calc = crc.create(params)
hash_f = calc.calc(data)


"""
use a different engine
        tableized is fastest engine but creates a table of 256 values
                this is the default
        generic doesn't create a table, but is slower
"""
# engine = crc.engines.generic
engine = crc.engines.tableized
calc = crc.create(params, engine)
hash_g = calc.calc(data)


"""
use the engine directly
        no 'convenience objects'
"""
# NotImplemented


"""
test
"""
hashes = check, zlib.crc32(data), hash_a, hash_c, hash_f, hash_g
assert all(h == check for h in hashes)
print(hashes)


if __name__ == '__main__':
        pass

Features

  • 01: …

Other featues:

License

CRCx is licensed under Mozilla Public License.

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

CRCx-0.0.4.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

CRCx-0.0.4-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file CRCx-0.0.4.tar.gz.

File metadata

  • Download URL: CRCx-0.0.4.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for CRCx-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ef6ab21bbd818c716837910042c35b52554db3b5c963179fa6bcd6c55e714495
MD5 aa2fc0374904ccdda7cfa05887d6f979
BLAKE2b-256 3af210452083e3536da099903fe5e433806de21fa7adb30938ad3178f3d18a11

See more details on using hashes here.

File details

Details for the file CRCx-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: CRCx-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for CRCx-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d91919dd04119087932a08d7803767bb4de37171bd0fab9a62e7f4e7079cc09f
MD5 fa3e791f63d9998be1eb95f2bcbf18d3
BLAKE2b-256 41c037bcc6f616bd6c5418529d10a3bff5dfb7e6b267934a2d461c1b7d39d3c6

See more details on using hashes here.

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