Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I was curious about CRC32 so I did a quick google search and it brought up some examples. They weren't all that exceptional so I figured I'd post here to get more information. From what I gathered, you take a message that is 32 bit of data in length, then shift it left bitwise 3 places. Take the lowest 5 bits from that message and add 1 to it which would become the checksum. you then append the checksum on the end of the message. To check you would take the message modulo the checksum and shouldn't have a remainder.Is that correct or did I not fully understand it?
-Sean
Posted
CRC32 is an algorithm that produces a 32 bit number for a given byte stream using polynomials. (Here's a good description: http://www34.brinkster.com/dizzyk/math-crc.asp ) It is used to verify that the byte stream hasn't been changed since a minor change in the stream would produce a completely different cheksum. Generally CRC32 is being phased out. If speed is important then Adler32 is favored otherwise the more secure MD5 or SHA1 is used mostly now days.
"Who is John Galt?"
Posted

Ok, I followed it (I think) and for some reason it doesn't come out right.. I'm thinking this is because you can choose any polynomial that you wish (Although I used the one for Ethernet). Any Ideas? Here is the code I used (I did it the slow way I guess, no lookup table).

 


#include "stdafx.h"
#include <iostream>
#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
ifstream mf;
char *b = new char();
unsigned long r = 0x04c11db7L;
unsigned long s = 0;
unsigned long t = 0;
unsigned long temp = 0;



mf.open("C:\\test.txt",ios::binary);

while(mf.peek() != -1)
{
s = r & 0xff000000;
cout<<mf.read(b,1);
s = s ^ *b;
temp = r & 0xFF000000;
temp = temp>>24;
r = r<<8;
r = r | temp;
s = s ^ r;
t = t + s;
}
mf.close();
cout<<endl<<r<<"|"<<s<<"|"<<t<<endl;
cin.get();
return 0;
}
[/Code]

-Sean

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...