secrets.js
function lagrange(at, x, y){
	var sum = 0,
		product, 
		i, j;
		
	for(var i=0, len = x.length; i<len; i++){
		if(!y[i]){
			continue; 
		}
			
		product = config.logs[y[i]];
		for(var j=0; j<len; j++){
			if(i === j){ continue; }
			if(at === x[j]){ // happens when computing a share that is in the list of shares used to compute it
				product = -1; // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1
				break; 
			}
			product = ( product + config.logs[at ^ x[j]] - config.logs[x[i] ^ x[j]] + config.max/* to make sure it's not negative */ ) % config.max;
		}
			
		sum = product === -1 ? sum : sum ^ config.exps[product]; // though exps[-1]= undefined and undefined ^ anything = anything in chrome, this behavior may not hold everywhere, so do the check
	}
	return sum;
}
function lagrange(at, x, y){
	var sum = 0,
		product, 
		i, j;
		
	for(var i=0, len = x.length; i<len; i++){
		if(!y[i]){
			continue; 
		}
			
		product = config.logs[y[i]];
		for(var j=0; j<len; j++){
			if(i === j){ continue; }
			if(at === x[j]){ // happens when computing a share that is in the list of shares used to compute it
				product = -1; // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1
				break; 
			}
			product = ( product + config.logs[at ^ x[j]] - config.logs[x[i] ^ x[j]] + config.max/* to make sure it's not negative */ ) % config.max;
		}
			
		sum = product === -1 ? sum : sum ^ config.exps[product]; // though exps[-1]= undefined and undefined ^ anything = anything in chrome, this behavior may not hold everywhere, so do the check
	}
	return sum;
}
function lagrange ( at , x , y ) { var sum = 0 , product , i , j ; for ( var i = 0 , len = x . length ; i < len ; i ++ ) { if ( ! y [ i ] ) { continue ; } product = config . logs [ y [ i ] ] ; for ( var j = 0 ; j < len ; j ++ ) { if ( i === j ) { continue ; } if ( at === x [ j ] ) { // happens when computing a share that is in the list of shares used to compute it product = - 1 ; // fix for a zero product term, after which the sum should be sum^0 = sum, not sum^1 break ; } product = ( product + config . logs [ at ^ x [ j ] ] - config . logs [ x [ i ] ^ x [ j ] ] + config . max /* to make sure it's not negative */ ) % config . max ; } sum = product === - 1 ? sum : sum ^ config . exps [ product ] ; // though exps[-1]= undefined and undefined ^ anything = anything in chrome, this behavior may not hold everywhere, so do the check } return sum ; }
Evaluate the Lagrange interpolation polynomial at x = `at` using x and y Arrays that are of the same length, with corresponding elements constituting points on the polynomial.
Evaluate the Lagrange interpolation polynomial at x = at using x and y Arrays that are of the same length with corresponding elements constituting points on the polynomial .