Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binascii.crc_hqx() implements CRC-CCITT #73190

Closed
vadmium opened this issue Dec 18, 2016 · 6 comments
Closed

binascii.crc_hqx() implements CRC-CCITT #73190

vadmium opened this issue Dec 18, 2016 · 6 comments
Labels
3.7 (EOL) end of life docs Documentation in the Doc dir

Comments

@vadmium
Copy link
Member

vadmium commented Dec 18, 2016

BPO 29004
Nosy @malemburg, @mdickinson, @ericvsmith, @vadmium, @serhiy-storchaka
Files
  • crc-ccitt.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-12-24.09:51:35.901>
    created_at = <Date 2016-12-18.10:52:31.417>
    labels = ['3.7', 'docs']
    title = 'binascii.crc_hqx() implements CRC-CCITT'
    updated_at = <Date 2016-12-24.09:51:35.900>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2016-12-24.09:51:35.900>
    actor = 'martin.panter'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2016-12-24.09:51:35.901>
    closer = 'martin.panter'
    components = ['Documentation']
    creation = <Date 2016-12-18.10:52:31.417>
    creator = 'martin.panter'
    dependencies = []
    files = ['45952']
    hgrepos = []
    issue_num = 29004
    keywords = ['patch']
    message_count = 6.0
    messages = ['283548', '283550', '283552', '283553', '283925', '283933']
    nosy_count = 8.0
    nosy_names = ['lemburg', 'mark.dickinson', 'eric.smith', 'stutzbach', 'docs@python', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue29004'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @vadmium
    Copy link
    Member Author

    vadmium commented Dec 18, 2016

    If I had known this it would have saved me getting a separate implementation working.

    >>> hex(binascii.crc_hqx(b"\x01", 0))
    '0x1021'
    https://files.stairways.com/other/binhex-40-specs-info.txt

    Documenting this might helped many other people. Top Google hits seem oblivious to crc_hqx(), using other CRC implementations, and even other helper functions from the binascii module:

    https://pypi.python.org/pypi/crc16
    http://stackoverflow.com/questions/26204060/calculate-crc-ccitt-0xffff-for-hex-string

    @vadmium vadmium added the 3.7 (EOL) end of life label Dec 18, 2016
    @vadmium vadmium added the docs Documentation in the Doc dir label Dec 18, 2016
    @serhiy-storchaka
    Copy link
    Member

    If document the polynomial for crc_hqx, maybe document it for crc32 and adler32?

    Wouldn't be better to write the formula as *x*\ :sup:`16` + *x*\ :sup:`12 + *x*\ :sup:`5` + 1 ?

    @vadmium
    Copy link
    Member Author

    vadmium commented Dec 18, 2016

    It seems I can write it without the escaped spaces. Is there a problem with this:

    *x*:sup:`16` + *x*:sup:`12` + *x*:sup:`5` + 1

    I’m happy to add the CRC-32 polynomial if you think it would be useful, although it is a lot longer (fifteen terms instead of four). And this CRC is already easily identified by the CRC-32 name. As well as the polynomial, there are other details that identify a CRC. The bits in CRC-32 are reversed and inverted compared to CRC-CCITT.

    >>> hex(crc32(b"\x80", 0xFFFFFFFF) ^ 0xFFFFFFFF)
    '0xedb88320'
    # 0xEDB88320 is the reversed polynomial representation; the x^0 term corresponds to bit 31

    Adler32 is not a CRC, and I don’t think there are multiple versions of the algorithm, so I don’t think it would need any special explanation.

    @serhiy-storchaka
    Copy link
    Member

    Okay, then the patch LGTM. Use the form of the polynomial that you prefer.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 24, 2016

    New changeset a33472f8a2c6 by Martin Panter in branch '3.5':
    Issue bpo-29004: Document binascii.crc_hqx() implements CRC-CCITT
    https://hg.python.org/cpython/rev/a33472f8a2c6

    New changeset 52db2072e88b by Martin Panter in branch '3.6':
    Issue bpo-29004: Merge crc_hqx() doc from 3.5
    https://hg.python.org/cpython/rev/52db2072e88b

    New changeset 3af3702b2f0a by Martin Panter in branch 'default':
    Issue bpo-29004: Merge crc_hqx() doc from 3.6
    https://hg.python.org/cpython/rev/3af3702b2f0a

    New changeset 5ae6102270df by Martin Panter in branch '2.7':
    Issue bpo-29004: Document binascii.crc_hqx() implements CRC-CCITT
    https://hg.python.org/cpython/rev/5ae6102270df

    @vadmium
    Copy link
    Member Author

    vadmium commented Dec 24, 2016

    Thanks for the help Serhiy

    @vadmium vadmium closed this as completed Dec 24, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants