This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: binascii.crc_hqx() implements CRC-CCITT
Type: Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.smith, lemburg, mark.dickinson, martin.panter, python-dev, serhiy.storchaka, stutzbach
Priority: normal Keywords: patch

Created on 2016-12-18 10:52 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
crc-ccitt.patch martin.panter, 2016-12-18 10:52 review
Messages (6)
msg283548 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-18 10:52
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
msg283550 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-18 11:13
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 ?
msg283552 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-18 11:47
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.
msg283553 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-18 11:53
Okay, then the patch LGTM. Use the form of the polynomial that you prefer.
msg283925 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-24 08:18
New changeset a33472f8a2c6 by Martin Panter in branch '3.5':
Issue #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 #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 #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 #29004: Document binascii.crc_hqx() implements CRC-CCITT
https://hg.python.org/cpython/rev/5ae6102270df
msg283933 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-24 09:51
Thanks for the help Serhiy
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73190
2016-12-24 09:51:35martin.pantersetstatus: open -> closed
resolution: fixed
messages: + msg283933

stage: patch review -> resolved
2016-12-24 08:18:25python-devsetnosy: + python-dev
messages: + msg283925
2016-12-18 11:53:11serhiy.storchakasetmessages: + msg283553
2016-12-18 11:47:52martin.pantersetmessages: + msg283552
2016-12-18 11:13:12serhiy.storchakasetnosy: + stutzbach, lemburg, eric.smith, mark.dickinson, serhiy.storchaka
messages: + msg283550
2016-12-18 10:52:31martin.pantercreate