I'm looking for a way to reverse a CRC64 checksum. I already have CRC32 reversing implementation, and it actually reverses the checksum to it's original value, if it's 32 Bits in length. I have simply nothing to create a CRC64 reverse implementation. I tried multiple times but failed to do so. It is completely beyond my ability, so I'm hoping someone can piece together an implementation in C#.
Here is the CRC32 reversing code in C# which is working:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MYC
{
public class Crc32Reverse
{
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);
List<uint> list = new List<uint>();
crc = wantcrc ^ startxor;
for (int i = length - 1; i >= fixpos; i--)
{
uint param0 = crc >> (3 * 8);
list.Add(param0);
crc = (crc << 8) ^ revtable[param0] ^ bytes[i];
}
Array.Copy(BitConverter.GetBytes(crc), 0, bytes, fixpos, 4);
}
public Crc32Reverse()
{
if (Crc32Reverse.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;
}
Crc32Reverse.table = table;
Crc32Reverse.revtable = revtable;
}
}
}
}
I have tried everything but I failed to create a CRC64 reverse code. It is beyond my ability.
User contributions licensed under CC BY-SA 3.0