CRC.java revision baa3858d3f5d128a5c8466b700098109edcad5f2
1// SevenZip/CRC.java 2 3package SevenZip; 4 5public class CRC 6{ 7 static public int[] Table = new int[256]; 8 9 static 10 { 11 for (int i = 0; i < 256; i++) 12 { 13 int r = i; 14 for (int j = 0; j < 8; j++) 15 if ((r & 1) != 0) 16 r = (r >>> 1) ^ 0xEDB88320; 17 else 18 r >>>= 1; 19 Table[i] = r; 20 } 21 } 22 23 int _value = -1; 24 25 public void Init() 26 { 27 _value = -1; 28 } 29 30 public void Update(byte[] data, int offset, int size) 31 { 32 for (int i = 0; i < size; i++) 33 _value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8); 34 } 35 36 public void Update(byte[] data) 37 { 38 int size = data.length; 39 for (int i = 0; i < size; i++) 40 _value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8); 41 } 42 43 public void UpdateByte(int b) 44 { 45 _value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8); 46 } 47 48 public int GetDigest() 49 { 50 return _value ^ (-1); 51 } 52} 53