github.com/Psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/sss/sss_test.go (about) 1 package sss 2 3 import ( 4 "fmt" 5 ) 6 7 func Example() { 8 secret := "well hello there!" // our secret 9 n := byte(30) // create 30 shares 10 k := byte(2) // require 2 of them to combine 11 12 shares, err := Split(n, k, []byte(secret)) // split into 30 shares 13 if err != nil { 14 fmt.Println(err) 15 return 16 } 17 18 // select a random subset of the total shares 19 subset := make(map[byte][]byte, k) 20 for x, y := range shares { // just iterate since maps are randomized 21 subset[x] = y 22 if len(subset) == int(k) { 23 break 24 } 25 } 26 27 // combine two shares and recover the secret 28 recovered := string(Combine(subset)) 29 fmt.Println(recovered) 30 31 // Output: well hello there! 32 }