1:   // StrangeCRC.cs - computes a crc used in the bziplib ... I don't think that
2:   //                 this is the 'standard' crc, please correct me, if I'm wrong
3:   // Copyright (C) 2001 Mike Krueger
4:   //
5:   // This file was translated from java, it was part of the GNU Classpath
6:   // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
7:   //
8:   // This program is free software; you can redistribute it and/or
9:   // modify it under the terms of the GNU General Public License
10:   // as published by the Free Software Foundation; either version 2
11:   // of the License, or (at your option) any later version.
12:   //
13:   // This program is distributed in the hope that it will be useful,
14:   // but WITHOUT ANY WARRANTY; without even the implied warranty of
15:   // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16:   // GNU General Public License for more details.
17:   //
18:   // You should have received a copy of the GNU General Public License
19:   // along with this program; if not, write to the Free Software
20:   // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21:   //
22:   // Linking this library statically or dynamically with other modules is
23:   // making a combined work based on this library.  Thus, the terms and
24:   // conditions of the GNU General Public License cover the whole
25:   // combination.
26:   // 
27:   // As a special exception, the copyright holders of this library give you
28:   // permission to link this library with independent modules to produce an
29:   // executable, regardless of the license terms of these independent
30:   // modules, and to copy and distribute the resulting executable under
31:   // terms of your choice, provided that you also meet, for each linked
32:   // independent module, the terms and conditions of the license of that
33:   // module.  An independent module is a module which is not derived from
34:   // or based on this library.  If you modify this library, you may extend
35:   // this exception to your version of the library, but you are not
36:   // obligated to do so.  If you do not wish to do so, delete this
37:   // exception statement from your version.
38:  
39:   using System;
40:  
41:   namespace ICSharpCode.SharpZipLib.Checksums {
42:       
43:       public class StrangeCRC : IChecksum
44:       {
45:           readonly static uint[] crc32Table = {
46:                                0x000000000x04c11db70x09823b6e0x0d4326d9,
47:                                0x130476dc0x17c56b6b0x1a864db20x1e475005,
48:                                0x2608edb80x22c9f00f0x2f8ad6d60x2b4bcb61,
49:                                0x350c9b640x31cd86d30x3c8ea00a0x384fbdbd,
50:                                0x4c11db700x48d0c6c70x4593e01e0x4152fda9,
51:                                0x5f15adac0x5bd4b01b0x569796c20x52568b75,
52:                                0x6a1936c80x6ed82b7f0x639b0da60x675a1011,
53:                                0x791d40140x7ddc5da30x709f7b7a0x745e66cd,
54:                                0x9823b6e00x9ce2ab570x91a18d8e0x95609039,
55:                                0x8b27c03c0x8fe6dd8b0x82a5fb520x8664e6e5,
56:                                0xbe2b5b580xbaea46ef0xb7a960360xb3687d81,
57:                                0xad2f2d840xa9ee30330xa4ad16ea0xa06c0b5d,
58:                                0xd4326d900xd0f370270xddb056fe0xd9714b49,
59:                                0xc7361b4c0xc3f706fb0xceb420220xca753d95,
60:                                0xf23a80280xf6fb9d9f0xfbb8bb460xff79a6f1,
61:                                0xe13ef6f40xe5ffeb430xe8bccd9a0xec7dd02d,
62:                                0x348670770x30476dc00x3d044b190x39c556ae,
63:                                0x278206ab0x23431b1c0x2e003dc50x2ac12072,
64:                                0x128e9dcf0x164f80780x1b0ca6a10x1fcdbb16,
65:                                0x018aeb130x054bf6a40x0808d07d0x0cc9cdca,
66:                                0x7897ab070x7c56b6b00x711590690x75d48dde,
67:                                0x6b93dddb0x6f52c06c0x6211e6b50x66d0fb02,
68:                                0x5e9f46bf0x5a5e5b080x571d7dd10x53dc6066,
69:                                0x4d9b30630x495a2dd40x44190b0d0x40d816ba,
70:                                0xaca5c6970xa864db200xa527fdf90xa1e6e04e,
71:                                0xbfa1b04b0xbb60adfc0xb6238b250xb2e29692,
72:                                0x8aad2b2f0x8e6c36980x832f10410x87ee0df6,
73:                                0x99a95df30x9d6840440x902b669d0x94ea7b2a,
74:                                0xe0b41de70xe47500500xe93626890xedf73b3e,
75:                                0xf3b06b3b0xf771768c0xfa3250550xfef34de2,
76:                                0xc6bcf05f0xc27dede80xcf3ecb310xcbffd686,
77:                                0xd5b886830xd1799b340xdc3abded0xd8fba05a,
78:                                0x690ce0ee0x6dcdfd590x608edb800x644fc637,
79:                                0x7a0896320x7ec98b850x738aad5c0x774bb0eb,
80:                                0x4f040d560x4bc510e10x468636380x42472b8f,
81:                                0x5c007b8a0x58c1663d0x558240e40x51435d53,
82:                                0x251d3b9e0x21dc26290x2c9f00f00x285e1d47,
83:                                0x36194d420x32d850f50x3f9b762c0x3b5a6b9b,
84:                                0x0315d6260x07d4cb910x0a97ed480x0e56f0ff,
85:                                0x1011a0fa0x14d0bd4d0x19939b940x1d528623,
86:                                0xf12f560e0xf5ee4bb90xf8ad6d600xfc6c70d7,
87:                                0xe22b20d20xe6ea3d650xeba91bbc0xef68060b,
88:                                0xd727bbb60xd3e6a6010xdea580d80xda649d6f,
89:                                0xc423cd6a0xc0e2d0dd0xcda1f6040xc960ebb3,
90:                                0xbd3e8d7e0xb9ff90c90xb4bcb6100xb07daba7,
91:                                0xae3afba20xaafbe6150xa7b8c0cc0xa379dd7b,
92:                                0x9b3660c60x9ff77d710x92b45ba80x9675461f,
93:                                0x8832161a0x8cf30bad0x81b02d740x857130c3,
94:                                0x5d8a90990x594b8d2e0x5408abf70x50c9b640,
95:                                0x4e8ee6450x4a4ffbf20x470cdd2b0x43cdc09c,
96:                                0x7b827d210x7f4360960x7200464f0x76c15bf8,
97:                                0x68860bfd0x6c47164a0x610430930x65c52d24,
98:                                0x119b4be90x155a565e0x181970870x1cd86d30,
99:                                0x029f3d350x065e20820x0b1d065b0x0fdc1bec,
100:                                0x3793a6510x3352bbe60x3e119d3f0x3ad08088,
101:                                0x2497d08d0x2056cd3a0x2d15ebe30x29d4f654,
102:                                0xc5a926790xc1683bce0xcc2b1d170xc8ea00a0,
103:                                0xd6ad50a50xd26c4d120xdf2f6bcb0xdbee767c,
104:                                0xe3a1cbc10xe760d6760xea23f0af0xeee2ed18,
105:                                0xf0a5bd1d0xf464a0aa0xf92786730xfde69bc4,
106:                                0x89b8fd090x8d79e0be0x803ac6670x84fbdbd0,
107:                                0x9abc8bd50x9e7d96620x933eb0bb0x97ffad0c,
108:                                0xafb010b10xab710d060xa6322bdf0xa2f33668,
109:                                0xbcb4666d0xb8757bda0xb5365d030xb1f740b4
110:                            };
111:           int globalCrc;
112:       
113:           public StrangeCRC() 
114:           {
115:               Reset();
116:           }
117:       
118:           public void Reset()
119:           {
120:               globalCrc = -1;
121:           }
122:       
123:           public long Value {
124:               get {
125:                   return ~globalCrc;
126:               }
127:           }
128:           
129:           public void Update(int inCh)
130:           {
131:               int temp = (globalCrc >> 24) ^ inCh;
132:               if (temp 0) {
133:                   temp 256 temp;
134:               }
135:               globalCrc = (int)((globalCrc << 8) ^ crc32Table[temp]);
136:           }
137:           
138:           public void Update(byte[] buf)
139:           {
140:               Update(buf0buf.Length);
141:           }
142:           
143:           public void Update(byte[] bufint offint len)
144:           {
145:               if (buf == null) {
146:                   throw new ArgumentNullException("buf");
147:               }
148:               
149:               if (off || len || off len buf.Length) {
150:                   throw new ArgumentOutOfRangeException();
151:               }
152:               
153:               for (int 0len; ++i) {
154:                   Update(buf[off++]);
155:               }
156:           }
157:       }
158:   }

This page was automatically generated by SharpDevelop.