Add toolkit (Part 2)

This commit is contained in:
R-YaTian 2022-09-01 14:27:15 +08:00 committed by GitHub
parent 97cb76f041
commit 3b98ded72e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,4 +141,37 @@ namespace Ekona.Helper
return new byte[] { b1, b2, b3, b4 };
}
}
public static class CRC32_alt
{
static UInt32[] Crc32Table;
private static void GetCRC32Table()
{
UInt32 Crc;
Crc32Table = new UInt32[256];
int i, j;
for (i = 0; i < 256; i++)
{
Crc = (UInt32)i;
for (j = 8; j > 0; j--)
{
if ((Crc & 1) == 1)
Crc = (Crc >> 1) ^ 0xEDB88320;
else
Crc = (Crc >> 1) ^ 0;
}
Crc32Table[i] = Crc;
}
}
public static UInt32 Get(byte[] buffer)
{
GetCRC32Table();
UInt32 value = 0xffffffff;
int len = buffer.Length;
for (int i = 0; i < len; i++)
{
value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ buffer[i]];
}
return value;
}
}
}