mirror of
https://github.com/arnaucube/shamirsecretsharing.git
synced 2026-02-07 03:26:45 +01:00
add lagrange interpolation js to wasm wrapper and parser of the data struct
This commit is contained in:
@@ -73,7 +73,7 @@ func unpackSharesAndI(sharesPacked [][]*big.Int) ([]*big.Int, []*big.Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LagrangeInterpolation calculates the secret from given shares
|
// LagrangeInterpolation calculates the secret from given shares
|
||||||
func LagrangeInterpolation(sharesGiven [][]*big.Int, p *big.Int) *big.Int {
|
func LagrangeInterpolation(p *big.Int, sharesGiven [][]*big.Int) *big.Int {
|
||||||
resultN := big.NewInt(int64(0))
|
resultN := big.NewInt(int64(0))
|
||||||
resultD := big.NewInt(int64(0))
|
resultD := big.NewInt(int64(0))
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func TestCreate(t *testing.T) {
|
|||||||
sharesToUse = append(sharesToUse, shares[2])
|
sharesToUse = append(sharesToUse, shares[2])
|
||||||
sharesToUse = append(sharesToUse, shares[1])
|
sharesToUse = append(sharesToUse, shares[1])
|
||||||
sharesToUse = append(sharesToUse, shares[0])
|
sharesToUse = append(sharesToUse, shares[0])
|
||||||
secr := LagrangeInterpolation(sharesToUse, p)
|
secr := LagrangeInterpolation(p, sharesToUse)
|
||||||
|
|
||||||
// fmt.Print("original secret: ")
|
// fmt.Print("original secret: ")
|
||||||
// fmt.Println(k)
|
// fmt.Println(k)
|
||||||
|
|||||||
@@ -43,7 +43,42 @@ func createShares(i []js.Value) {
|
|||||||
println("error generating the shares")
|
println("error generating the shares")
|
||||||
}
|
}
|
||||||
println(shares)
|
println(shares)
|
||||||
|
sharesStr := sharesToString(shares)
|
||||||
|
println(sharesStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sharesToString(shares [][]*big.Int) []string {
|
||||||
|
var s []string
|
||||||
|
for i := 0; i < len(shares); i++ {
|
||||||
|
s = append(s, shares[i][0].String())
|
||||||
|
s = append(s, shares[i][1].String())
|
||||||
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func lagrangeInterpolation(i []js.Value) {
|
func lagrangeInterpolation(i []js.Value) {
|
||||||
|
p, ok := new(big.Int).SetString(i[0].String(), 10)
|
||||||
|
if !ok {
|
||||||
|
println("error parsing parameter in position 0 (p)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse the shares array
|
||||||
|
var shares [][]*big.Int
|
||||||
|
for n := 1; n < len(i); n = n + 2 {
|
||||||
|
a, ok := new(big.Int).SetString(i[n].String(), 10)
|
||||||
|
if !ok {
|
||||||
|
println("error parsing parameter in position ", n)
|
||||||
|
}
|
||||||
|
b, ok := new(big.Int).SetString(i[n+1].String(), 10)
|
||||||
|
if !ok {
|
||||||
|
println("error parsing parameter in position ", n+1)
|
||||||
|
}
|
||||||
|
var share []*big.Int
|
||||||
|
share = append(share, a)
|
||||||
|
share = append(share, b)
|
||||||
|
shares = append(shares, share)
|
||||||
|
}
|
||||||
|
|
||||||
|
secr := shamirsecretsharing.LagrangeInterpolation(p, shares)
|
||||||
|
println(secr.String())
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user