1 /***********************************************************************
2 * Coded by Ketmar // Invisible Vector
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 ***********************************************************************/
18 module iv
.oldpakerz
.crc32
/*is aliced*/;
22 public uint wdx_crc32 (const(void)[] buf
, uint crc
=0) pure nothrow @trusted @nogc {
24 static immutable uint[16] crctab = [
25 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
26 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
27 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
28 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c,
31 static immutable uint[16] crctab
= {
33 // make exclusive-or pattern from polynomial (0xedb88320u)
34 // terms of polynomial defining this crc (except x^32)
35 //uint poly = 0; // polynomial exclusive-or pattern
36 //foreach (immutable n; [0,1,2,4,5,7,8,10,11,12,16,22,23,26]) poly |= 1u<<(31-n);
37 enum poly
= 0xedb88320u
;
38 foreach (immutable n
; 0..16) {
39 uint c
= cast(uint)n
*16;
40 foreach (immutable k
; 0..8) c
= (c
&1 ? poly^
(c
>>1) : c
>>1);
48 foreach (ubyte b
; cast(const(ubyte)[])buf
) {
50 crc
= crctab
.ptr
[crc
&0x0f]^
(crc
>>4);
51 crc
= crctab
.ptr
[crc
&0x0f]^
(crc
>>4);