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

In crc16 function ,can we add other polynomials? #69

Open
Tengfei1010 opened this issue Nov 17, 2014 · 2 comments
Open

In crc16 function ,can we add other polynomials? #69

Tengfei1010 opened this issue Nov 17, 2014 · 2 comments

Comments

@Tengfei1010
Copy link

Hi, I find crc16 algorithms has many other polynomials.
In helper.py, crc16 function is:
"
def crc16(string, value=0):
"""
CRC-16 poly: p(x) = x16 + x15 + x**2 + 1
"""
crc16_table = []
for byte in range(256):
crc = 0

    for bit in range(8):
        if (byte ^ crc) & 1:
            crc = (crc >> 1) ^ 0xa001  # polly
        else:
            crc >>= 1

        byte >>= 1

    crc16_table.append(crc)

for ch in string:
    value = crc16_table[ord(ch) ^ (value & 0xff)] ^ (value >> 8)

return value

"

and I am not sure the funtion can be writen like this:
"
def crc16(string, value=0xa001):
"""
CRC-16 poly: p(x) = x16 + x15 + x**2 + 1
@:param value:
CRC-16 model
P_16 0xa001
P_CCITT 0x1021
P-DNP 0xa6bc
p_KERMIT 0x8408
P_SICK 0x8005
"""
crc16_table = []
for byte in range(256):
crc = 0

    for bit in range(8):
        if (byte ^ crc) & 1:
            crc = (crc >> 1) ^ value  # poly
        else:
            crc >>= 1

        byte >>= 1

    crc16_table.append(crc)

for ch in string:
    value = crc16_table[ord(ch) ^ (value & 0xff)] ^ (value >> 8)

return value

"

@Fitblip
Copy link
Member

Fitblip commented Nov 17, 2014

Hi there,

I'm not sure I follow with all the in-line text. Can you re-format your question with proper markdown, or submit a PR?

Thanks!

@Tengfei1010
Copy link
Author

ok, I am sorry. I do not have a clear descrption of the problem. Meanwhile, I have another question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants