我正在寻找一种逆转a CRC32 checksum的方法。周围有解决方案,但它们要么是badly written,要么是extremely technical和/或in Assembly。汇编语言(目前)超出了我的能力范围,所以我希望有人能用更高级的语言拼凑出一个实现。Ruby很理想,但我可以解析PHP、Python、C、Java等。
有谁愿意接受吗?
发布于 2009-10-03 15:28:25
只有当原始字符串小于或等于4个字节时,CRC32才是可逆的。
发布于 2009-10-22 23:28:19
阅读the document called "Reversing CRC Theory and Practice"。
这是C#:
public class Crc32
{
public const uint poly = 0xedb88320;
public const uint startxor = 0xffffffff;
static uint[] table = null;
static uint[] revtable = null;
public void FixChecksum(byte[] bytes, int length, int fixpos, uint wantcrc)
{
if (fixpos + 4 > length) return;
uint crc = startxor;
for (int i = 0; i < fixpos; i++) {
crc = (crc >> 8) ^ table[(crc ^ bytes[i]) & 0xff];
}
Array.Copy(BitConverter.GetBytes(crc), 0, bytes, fixpos, 4);
crc = wantcrc ^ startxor;
for (int i = length - 1; i >= fixpos; i--) {
crc = (crc << 8) ^ revtable[crc >> (3 * 8)] ^ bytes[i];
}
Array.Copy(BitConverter.GetBytes(crc), 0, bytes, fixpos, 4);
}
public Crc32()
{
if (Crc32.table == null) {
uint[] table = new uint[256];
uint[] revtable = new uint[256];
uint fwd, rev;
for (int i = 0; i < table.Length; i++) {
fwd = (uint)i;
rev = (uint)(i) << (3 * 8);
for (int j = 8; j > 0; j--) {
if ((fwd & 1) == 1) {
fwd = (uint)((fwd >> 1) ^ poly);
} else {
fwd >>= 1;
}
if ((rev & 0x80000000) != 0) {
rev = ((rev ^ poly) << 1) | 1;
} else {
rev <<= 1;
}
}
table[i] = fwd;
revtable[i] = rev;
}
Crc32.table = table;
Crc32.revtable = revtable;
}
}
}发布于 2009-10-03 15:58:35
凯德·鲁克斯关于逆转CRC32的看法是正确的。
您提到的链接提供了一种解决方案,用于修复通过更改原始字节流而失效的CRC。此修复是通过更改一些(不重要的)字节来实现的,因此可以重新创建原始CRC值。
https://stackoverflow.com/questions/1514040
复制相似问题