CRC (Cyclic Redundancy Checksum) is a quick method to compute a value (or sometimes known as hash), that can be used to represent the data integrity. CRC32 computes a 32-bit integer (signed or unsigned) from a given source (text, string).
CRC32 is easy to implement. First, define a table of 256 values. The table can be found [here]. Then for each element from source, do the following operation
r = (r >> 8) ^ CRCTable[str[i] ^ (r & 0x000000FF)];
where r stores the intermediate result.
A Javascript implementation can be found online at https://rot47.net/crc32.html
However, since a 32-bit integer can only store
CRC32 is NOT used in security areas (storing passwords) such as MD5 where data conflicting is of importance.
The following is a Javascript source code (only a partial table is given) that gives the CRC32 in a function, which can be used easily.
/*
CRC32.js
compute Cyclic redundancy check
Dr justyy
https://rot47.net/crc32.html
*/
var CRC32 = function(str){
var CRCTable = [
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
// lots of data leading up to 256 elements ...
];
var len = str.length;
var r = 0xffffffff;
for (var i = 0; i < len; i ++) {
r = (r >> 8) ^ CRCTable[str[i] ^ (r & 0x000000FF)];
}
return ~r;
}
The Javascript CRC32 implementation together with HTML can be found at [here]
References:
[1] http://en.wikipedia.org/wiki/Cryptographic_hash_function
[2] http://en.wikipedia.org/wiki/MD5
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Codeforces: 347 B. Fixed Points
Next Post: Picture Explorer, Sort Pictures by Facebook Likes