1370b324cSopenharmony_ci// SevenZip/CRC.java
2370b324cSopenharmony_ci
3370b324cSopenharmony_cipackage SevenZip;
4370b324cSopenharmony_ci
5370b324cSopenharmony_cipublic class CRC
6370b324cSopenharmony_ci{
7370b324cSopenharmony_ci	static public int[] Table = new int[256];
8370b324cSopenharmony_ci
9370b324cSopenharmony_ci	static
10370b324cSopenharmony_ci	{
11370b324cSopenharmony_ci		for (int i = 0; i < 256; i++)
12370b324cSopenharmony_ci		{
13370b324cSopenharmony_ci			int r = i;
14370b324cSopenharmony_ci			for (int j = 0; j < 8; j++)
15370b324cSopenharmony_ci				if ((r & 1) != 0)
16370b324cSopenharmony_ci					r = (r >>> 1) ^ 0xEDB88320;
17370b324cSopenharmony_ci				else
18370b324cSopenharmony_ci					r >>>= 1;
19370b324cSopenharmony_ci			Table[i] = r;
20370b324cSopenharmony_ci		}
21370b324cSopenharmony_ci	}
22370b324cSopenharmony_ci
23370b324cSopenharmony_ci	int _value = -1;
24370b324cSopenharmony_ci
25370b324cSopenharmony_ci	public void Init()
26370b324cSopenharmony_ci	{
27370b324cSopenharmony_ci		_value = -1;
28370b324cSopenharmony_ci	}
29370b324cSopenharmony_ci
30370b324cSopenharmony_ci	public void Update(byte[] data, int offset, int size)
31370b324cSopenharmony_ci	{
32370b324cSopenharmony_ci		for (int i = 0; i < size; i++)
33370b324cSopenharmony_ci			_value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);
34370b324cSopenharmony_ci	}
35370b324cSopenharmony_ci
36370b324cSopenharmony_ci	public void Update(byte[] data)
37370b324cSopenharmony_ci	{
38370b324cSopenharmony_ci		int size = data.length;
39370b324cSopenharmony_ci		for (int i = 0; i < size; i++)
40370b324cSopenharmony_ci			_value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);
41370b324cSopenharmony_ci	}
42370b324cSopenharmony_ci
43370b324cSopenharmony_ci	public void UpdateByte(int b)
44370b324cSopenharmony_ci	{
45370b324cSopenharmony_ci		_value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);
46370b324cSopenharmony_ci	}
47370b324cSopenharmony_ci
48370b324cSopenharmony_ci	public int GetDigest()
49370b324cSopenharmony_ci	{
50370b324cSopenharmony_ci		return _value ^ (-1);
51370b324cSopenharmony_ci	}
52370b324cSopenharmony_ci}
53