tricky crc algorithm

帅比萌擦擦* 提交于 2019-12-03 20:43:00

First, 4 hex digits aren't 4 bytes. Since all your examples show 4 hex digits -- 2 bytes -- I'll assume you mean 2 bytes.

There are only 65,536 distinct hash values, here's what you do.

Execute the hash function for all 65,536 values from 0000 to FFFF. Tabulate the results. That table is the function. It maps input value to output value.

While lame, it's always correct, it's not terribly big (65K bytes), and it's really fast after you've done the calculation.

You can't reverse engineer hash functions very easily. The good ones are sophisticated state machines that use all of the input bits in some "fair" way so that the output values are dramatically different for input values that differ by only a few bits.

If you compare 0000 with 0001, 0002, 0004, 0008, 0010, 0020, 0040, 0080, 0100, 0200, 0400, 0800, 1000, 2000, 4000 and 8000, you might be able to figure out what each bit contributes to the hash. But I doubt it.

Assuming they are two byte (16 bit) values, I've tried a few on some online CRC generators without getting your results. So it looks like it's not a commonly used CRC algorithm.

Do you have any clues about the likely algorithm? Or is this a homework assignment and you're supposed to reverse-engineer the CRC algorithm/parameters?

Summary: more information needed.

A CRC is simply division, just like you learn long-hand division in grade school except that add and subtract are replaced with XOR. So what you need to do is solve the following equations in GF(2):

CE1E % p = 03
CE20 % p = 45
CE22 % p = 6F
0000 % p = C0
0001 % p = D4
FFFF % p = 95

There is no polynomial p for which 0000%p = c0. (0 modulo p is 0 for all values of p.) So maybe it's (x+input) % p = crc. In your case, x must be c0. If that's true, then (x+0001)%p must be c1. Looks like it isn't a CRC at all. If you're determined and you believe that the answer is linear, make a matrix of zeroes and ones that is invertible and solve the set of equations that arises from your matrix times input = output. You'll need more inputs, though.

http://www.geocities.com/SiliconValley/Pines/8659/crc.htm#r2

It looks to my inexperienced eyes that you will have to implement a general crc algorithm and try it out with several polys (try the "popular" ones mentioned in that article first).

edit: after further reading, it seems that you have to take into account reverse polys too.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!