- var accum, count, formula, startposition, nextposition, value, numerator, denominator;
- for(formula = accum = 0; formula < shares.length; formula++) {
- for(count = 0, numerator = denominator = 1; count < shares.length; count++) {
- if(formula == count) continue; // If not the same value
- startposition = shares[formula][0];
- nextposition = shares[count][0];
- numerator = (numerator * -nextposition) % prime;
- denominator = (denominator * (startposition - nextposition)) % prime;
+ var sum = 0;
+
+ for(j = 0; j < shares.length; j++) {
+ var numerator = 1;
+ var denominator = 1;
+ for(m = 0; m < shares.length; m++) {
+ if(j == m) continue; // If not the same value
+ numerator = (numerator * shares[m].share_number) % prime;
+ denominator = (denominator * (shares[m].share_number - shares[j].share_number)) % prime;