More Awesome Than You!
Welcome, Guest. Please login or register.
2024 April 27, 11:22:02

Login with username, password and session length
Search:     Advanced search
540270 Posts in 18066 Topics by 6513 Members
Latest Member: Linnie
* Home Help Search Login Register
+  More Awesome Than You!
|-+  TS2: Burnination
| |-+  The Podium
| | |-+  Need an algorithm to generate CRC32 hash
0 Members and 1 Chinese Bot are viewing this topic. « previous next »
Pages: [1] THANKS THIS IS GREAT Print
Author Topic: Need an algorithm to generate CRC32 hash  (Read 4511 times)
wes_h
Knuckleheaded Knob
**
Posts: 530


Lady on Rancho Como


View Profile
Need an algorithm to generate CRC32 hash
« on: 2007 April 11, 03:29:00 »
THANKS THIS IS GREAT

A long time ago, I had a copy of an algorithm to generate the CRC32 value used as the InstanceHi (or Subtype) field in the TGI. Of course, I lost it, since it was always so easy to go to SimPE and use the hash generator. Now, I have a project I am working on that needs to have this hard-coded in.

The only real meaty resource specfically related to Maxis' usage I located states it is generated using the parameters:

Resource ID: CRC-32 (Poly=0x04C11DB7, Seed=0xFFFFFFFF, reflection=false, XOR Output=0x00000000)

I found plenty of CRC32 examples using that poly value, being the algorithm used for WinZIP and others. However, they all had a reflection part in the routine that I did not see as being any kind of boolean operation.

So what I am asking for is a pointer to a working routine for this... any programming language is fine.

<* Wes *>
Logged
dizzy
Souped!
*
Posts: 1572


unplugged


View Profile
Re: Need an algorithm to generate CRC32 hash
« Reply #1 on: 2007 April 11, 11:34:09 »
THANKS THIS IS GREAT

I did something like this before...

http://www.moreawesomethanyou.com/smf/index.php?topic=6650.msg187881#msg187881
Logged

wes_h
Knuckleheaded Knob
**
Posts: 530


Lady on Rancho Como


View Profile
Re: Need an algorithm to generate CRC32 hash
« Reply #2 on: 2007 April 12, 02:22:15 »
THANKS THIS IS GREAT

But I USED search! Smiley

I was hoping YOU had done that before.
I have copied the routine and will work with it.
I appreciate the help.

<* Wes *>
Logged
wes_h
Knuckleheaded Knob
**
Posts: 530


Lady on Rancho Como


View Profile
Re: Need an algorithm to generate CRC32 hash
« Reply #3 on: 2007 May 22, 04:11:21 »
THANKS THIS IS GREAT

OK, I was unable to make the algorithm for CRC32 you posted work.

In case you, or anyone else, is in burning need of this routine, I am posting the code I found posted on the internet (as modified by me) that will calculate the CRC32 the same way that the game and SimPE calculate it. It ain't pretty, and I didn't worry about optimizing it because I use it once per bone for exporting animation data. The two lines commented out are for a bit reflection routine I didn't include, or need:

Code:
unsigned long crcbitbybitfast(unsigned char* p) {

// fast bit by bit algorithm without augmented zero bytes.
// does not use lookup table, suited for polynom orders between 1...32.

unsigned long i, j, c, bit;
unsigned long crc = 0xffffffff;
unsigned long crchighbit = 0x80000000;
unsigned long polynom = 0x04c11db7;
unsigned long crcxor = 0;
unsigned long crcmask = 0xFFFFFFFF;
unsigned long order = 32;
unsigned long len;

len=strlen(p);

for (i=0; i<len; i++) {
c = (unsigned long)*p++;
// if (refin) c = reflect(c, 8);
for (j=0x80; j; j>>=1) {
bit = crc & crchighbit;
crc<<= 1;
if (c & j) bit^= crchighbit;
if (bit) crc^= polynom;
}
}
// if (refout) crc=reflect(crc, order);
crc^= crcxor;
crc&= crcmask;
return(crc);
}
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.072 seconds with 20 queries.