OpenRCE / sulley

A pure-python fully automated and unattended fuzzing framework.
GNU General Public License v2.0
1.42k stars 338 forks source link

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

Open Tengfei1010 opened 9 years ago

Tengfei1010 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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