namespace Crysome.Common.Network.FileTransfer;

internal static class Crc32
{
	private static readonly uint[] _table = Build();

	private static uint[] Build()
	{
		uint[] array = new uint[256];
		for (uint num = 0u; num < 256; num++)
		{
			uint num2 = num;
			for (int i = 0; i < 8; i++)
			{
				num2 = (((num2 & 1) != 0) ? (0xEDB88320u ^ (num2 >> 1)) : (num2 >> 1));
			}
			array[num] = num2;
		}
		return array;
	}

	internal static uint Compute(byte[] data, int offset, int len)
	{
		uint num = uint.MaxValue;
		int num2 = offset + len;
		for (int i = offset; i < num2; i++)
		{
			num = (num >> 8) ^ _table[(num ^ data[i]) & 0xFF];
		}
		return num ^ 0xFFFFFFFFu;
	}
}
