棘手的 CRC 算法

发布于 2024-07-08 14:12:39 字数 159 浏览 10 评论 0原文

我正在尝试找到适用于以下结果的 crc。 字节字符串由 2 个字节(即 0xCE1E)组成,crc 是一个字节(即 0x03)

byte crc
CE1E 03
CE20 45
CE22 6F
0000 C0
0001 D4
FFFF 95

有人可以帮忙吗?

I am trying to find the crc that works with the following results. The byte string consists of 2 bytes (ie. 0xCE1E) and the crc is an single byte (ie. 0x03)

byte crc
CE1E 03
CE20 45
CE22 6F
0000 C0
0001 D4
FFFF 95

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月无声 2024-07-15 14:12:39

首先,4 个十六进制数字不是 4 个字节。 由于您的所有示例都显示 4 个十六进制数字(2 个字节),因此我假设您的意思是 2 个字节。

只有 65,536 个不同的哈希值,这就是您要做的。

对从 0000 到 FFFF 的所有 65,536 个值执行哈希函数。 将结果制成表格。 该表就是函数。 它将输入值映射到输出值。

虽然很蹩脚,但它总是正确的,它不是很大(65K 字节),而且在完成计算后它真的很快。

您无法轻松地对哈希函数进行逆向工程。 好的状态机是复杂的状态机,它们以某种“公平”的方式使用所有输入位,因此对于仅相差几个位的输入值,输出值会显着不同。

如果将 0000 与 0001、0002、0004、0008、0010、0020、0040、0080、0100、0200、0400、0800、1000、2000、4000 和 8000 进行比较,您也许能够计算出每一位对哈希。 但我对此表示怀疑。

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.

那小子欠揍 2024-07-15 14:12:39

假设它们是两个字节(16 位)值,我在一些在线 CRC 生成器上尝试了一些,但没有得到结果。 所以看起来这不是一个常用的CRC算法。

您对可能的算法有任何线索吗? 或者这是一项家庭作业,您应该对 CRC 算法/参数进行逆向工程?

摘要:需要更多信息。

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.

拥抱没勇气 2024-07-15 14:12:39

CRC 就是除法,就像你在小学学习的普通除法一样,只不过加法和减法被 XOR 代替。 因此,您需要做的是求解 GF(2) 中的以下方程:

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

不存在 0000%p = c0 的多项式 p。 (对于 p 的所有值,0 模 p 都是 0。)所以也许是 (x+input) % p = crc。 在你的情况下,x 必须是 c0。 如果这是真的,那么 (x+0001)%p 一定是 c1。 看起来它根本不是 CRC。 如果您下定决心并且相信答案是线性的,请制作一个由 0 和 1 组成的可逆矩阵,并求解由矩阵乘以输入 = 输出得出的方程组。 不过,您将需要更多输入。

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.

深陷 2024-07-15 14:12:39

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

在我缺乏经验的看来,您将必须实现一个通用的 crc 算法并尝试使用多个多边形(首先尝试该文章中提到的“流行”算法)。

编辑:进一步阅读后,似乎您也必须考虑反向多边形。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文