#1 Re: mORMot 1 » Javascript authentication » 2014-01-16 21:01:24

Here's a proper crc32 function:

    var makeCRCTable = function(){
        var c;
        var crcTable = [];
        for(var n =0; n < 256; n++){
            c = n;
            for(var k =0; k < 8; k++){
                c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
            }
            crcTable[n] = c;
        }
        return crcTable;
    }
    var crcTable = makeCRCTable();

    var crc32 = function(str, init) {
        var crc = (typeof init === 'undefined') ? 0 ^ (-1) : init^0xFFFFFFFF;
    
        for (var i = 0; i < str.length; i++ ) {
            crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
        }
    
        return (crc ^ (-1)) >>> 0;
    };

Board footer

Powered by FluxBB