lagrange interpolation for reconstructing shamir secret sharing

Hi guys, i`m currently having trouble with implementing a lagrange interpolation scheme for the reconstruction of shamir secret sharing .

the formula is as follows on the wikipedia website.

i saw the javascript example on wiki on this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function join(shares)
{
 var accum, count, formula, startposition, nextposition, value, numerator, denominator;
 for(formula = accum = 0; formula < shares.length; formula++)
 {
  /*
   * Multiply the numerator across the top and denominators across the bottom to do Lagrange's interpolation
   * Result is x0(2), x1(4), x2(5) -> -4*-5 and (2-4=-2)(2-5=-3), etc for l0, l1, l2...
   */
  for(count = 0, numerator = denominator = 1; count < shares.length; count++)
  {
   if(formula == count) continue; // If not the same value
   startposition = shares[formula][0];
   value = shares[formula][1];
   nextposition = shares[count][0];
   numerator = (numerator * -nextposition) % prime;
   denominator = (denominator * (startposition - nextposition)) % prime;
  }
  accum = (prime + accum + (shares[formula][1] * numerator / denominator)) % prime;
 }
 return accum;
}


may i know how to do it in c++?
i`m quite lost on this formula.
Any help would be appreciated! thanks in advance!
Topic archived. No new replies allowed.