This is a direct translation of the original code
function findNonce( data ){
var buffer, i, hash, nonce = -1;
data = '' + ( data || '' );
do {
hash = 0;
nonce++;
buffer = data + nonce;
i = buffer.length;
while(i--) hash += buffer.charCodeAt(i) * (i+1);
} while ( hash % 1234 );
return nonce;
};
And, once minified,
function findNonce(n){var e,o,r,t=-1;n=""+(n||"");do for(r=0,t++,e=n+t,o=e.length;o--;)r+=e.charCodeAt(o)*(o+1);while(r%1234);return t}
But if better performance is required this should be optimized, calculating first the hash for the input string and then doing only the calcs for each nonce value.
function findNonceFast( data ){
var preHash, noncePos, nonce = -1, code;
function hashCalc( s, hash, pos ){
var i = s.length; while(i--) hash += s.charCodeAt(i) * (i+pos+1);
return hash;
};
data = '' + ( data || '' );
preHash = hashCalc( data, 0, 0 );
noncePos = data.length;
do {
nonce++;
code = hashCalc( ''+nonce, preHash, noncePos );
} while (code % 1234)
return nonce;
};
Minified
function findNonceFast(n){function r(n,r,t){for(var e=n.length;e--;)r+=n.charCodeAt(e)*(e+t+1);return r}var t,e,o,a=-1;n=""+(n||""),t=r(n,0,0),e=n.length;do a++,o=r(""+a,t,e);while(o%1234);return a}