calculate the crc32 of a wxString

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
SuperPat
Knows some wx things
Knows some wx things
Posts: 29
Joined: Sat Nov 19, 2005 4:05 pm
Location: France - Center

calculate the crc32 of a wxString

Post by SuperPat »

Hello,

How to calculate the crc32 string of a wxString?
Currently developing, with wxWidgets, an open sources multi-platform (Windows, Linux, MacOs) download manager/accelerator with an Web sites aspiration function named SPGet:
http://spget.sourceforge.net/
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Not that hard. You can start with a 32 bits begin hash (you will have to find a hastable) and then do the following:

- Fetch byte
- Shift byte into 32 bits from the left
- XOR with previous hash
- Set new hash as previous one

And continue to do this until you have shifted all bytes in there. You end up with a CRC32 hash you can use to test if your data is changed or not.

There are better ways, I think for more certaintly changed contents arte spotted. you should use a MD5 checksum. This one is more powerful.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

Jorg wrote: - Shift byte (8 bits) into 32 bits from the left
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Hi,

Isn't that what I wrote? Anyway, if it was unclear thanks for clarifiying for me ;-) It was written around 10:00 dutch time so I am pretty impressed with my own clarification at that hour :P

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

For me it sounds like, that you want to shift 8 bits byte 32 bits left, that makes the value 0. May be I am wrong, but that what I make it out of the text.
NB: English is not the first language for me and many members here.
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
If you need a quick solution, wxChecksums (http://wxchecksums.sourceforge.net/mainpage_en.html) has support for CRC32, MD5 and SFV.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Ahh ok. No that's not what I meant.

Good call upCASE :-) I still believe MD5 is better then CRC32. But it all depends on where you are going to use it for, or what the performance will be.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Jorg wrote:Good call upCASE :-) I still believe MD5 is better then CRC32. But it all depends on where you are going to use it for, or what the performance will be.
Yes, it really depends as CRC and MD5 are more or less completely different. CRC, as the name suggest, is a cyclic redundancy algo, whereas MD5 is a hashing algo.
With CRC32 you can identify bit errors and (if I'm not mistaken) correct one bit erros. With MD5 this is not possible. But MD5 is more "secure".
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia »

Quick note that its under GPL license, one more dll :D
Post Reply