I need to compute a CRC 128 bit checksum for strings extracted from documents.
I am looking around on the internet but cant find any pseudo code or java code.
So anyone can help me?
Thanks for your attention.
I need to compute a CRC 128 bit checksum for strings extracted from documents.
I am looking around on the internet but cant find any pseudo code or java code.
So anyone can help me?
Thanks for your attention.
The wikipedia article on the computation of crc-checksums contains explanations on crc algorithms and shows pseudocode as well
http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
This is totally untested... However, here is a snippet for CRC checksuming of a string... Changing the Width will alter whether it is an 8 bit, 16 bit, 32 bit, 64 bit, etc. The return type would also need to be altered if you need to full size.
Ie setting width to 8 * 16, should result in a return that is the bottom most 64 bits `
static int WIDTH = (8 * 16);// change this to 8*4 for int, and 8 * 2 for 16 bits
static int TOPBIT = (1 << (WIDTH - 1));
static int POLYNOMIAL = 0xD8; /* 11011 followed by 0's */
static long CRCFunc(final String msg)
{
final byte message[] = msg.getBytes();
int nBytes = message.length;
if(nBytes<1) return 0;
long rem = 0;
int b;
for(b=0;b<nBytes;++b)
{
rem ^= (message[b] << (WIDTH - 8));
byte bit;
for(bit=8;bit>0;--bit)
{
if ((rem & TOPBIT)>0)
{
rem = (rem<< 1) ^ POLYNOMIAL;
}
else
{
rem = (rem << 1);
}
}
}
return (rem);
}
`