Well, the first time publish their source code.
Code:
byte[] lpFileBuffer = null;
// ----
using (FileStream fs = new FileStream(FilePath, FileMode.Open))
{
lpFileBuffer = new byte[fs.Length];
// ----
fs.Read(lpFileBuffer, 0, lpFileBuffer.Length);
}
// ----
int iCoresCount = Environment.ProcessorCount;
// ----
uint uSize = (uint)lpFileBuffer.Length;
// ----
uint dwMaskLength = (uint)(uSize / 4);
int iMaskLength = (int)(uSize / 4);
// ----
g_Config.Mask = new uint[dwMaskLength];
// ----
Stopwatch sw = new Stopwatch();
sw.Start();
// ----
ParallelOptions po = new ParallelOptions();
// ----
po.MaxDegreeOfParallelism = Environment.ProcessorCount;
// ----
Parallel.For(0, iMaskLength, po, i =>
{
g_Config.Mask[i] = BitConverter.ToUInt32(lpFileBuffer, i * 4);
});
// ----
Parallel.For(0, 1024, po, (i, loopState) =>
{
if (g_Config.bShouldStop == false)
{
g_Config.csf.Checksums[i] = GetChecksum(lpFileBuffer, g_Config.Mask, dwMaskLength, (ushort)i);
}
else
{
loopState.Stop();
}
});
// ----
sw.Stop();
// ----
public uint GetChecksum(byte[] lpFileBuffer, uint[] Mask, uint dwMaskLength, ushort wChecksumKey)
{
uint dwResult = (uint)(wChecksumKey << 9);
// ----
uint dwKey = 0;
// ----
for (uint i = 0, j = 0; i < dwMaskLength; i++, j += 4)
{
dwKey = Mask[i];
// ----
switch (((j >> 2) + wChecksumKey) % 3)
{
case 0:
{
dwResult ^= dwKey;
}
break;
case 1:
{
dwResult += dwKey;
}
break;
case 2:
{
dwResult = (dwResult << (int)(dwKey % 11)) ^ dwKey;
}
break;
default: break;
}
// ----
dwResult ^= ((wChecksumKey + dwResult) >> (int)(((j >> 2) % 16) + 3));
}
// ----
return dwResult;
}