-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrc32.cs
58 lines (52 loc) · 1.39 KB
/
Crc32.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Google_Bookmarks_Manager_for_GPOs
{
public class Crc32 : HashAlgorithm
{
private static readonly uint[] Table;
private uint _crc;
static Crc32()
{
const uint polynomial = 0xedb88320;
Table = new uint[256];
for (uint i = 0; i < 256; i++)
{
uint crc = i;
for (int j = 8; j > 0; j--)
{
if ((crc & 1) == 1)
crc = (crc >> 1) ^ polynomial;
else
crc >>= 1;
}
Table[i] = crc;
}
}
public Crc32()
{
HashSizeValue = 32;
}
public override void Initialize()
{
_crc = 0xffffffff;
}
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
for (int i = ibStart; i < cbSize; i++)
{
byte index = (byte)((_crc & 0xff) ^ array[i]);
_crc = (_crc >> 8) ^ Table[index];
}
}
protected override byte[] HashFinal()
{
_crc = ~_crc;
return BitConverter.GetBytes(_crc);
}
}
}