Skip to content

Instantly share code, notes, and snippets.

@aaronjanse
Last active May 31, 2018 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronjanse/6d9ec8bd48ec31bb14efde34bd657390 to your computer and use it in GitHub Desktop.
Save aaronjanse/6d9ec8bd48ec31bb14efde34bd657390 to your computer and use it in GitHub Desktop.
An easy way to do shamir secret sharing from the command line
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
sssa "github.com/SSSAAS/sssa-golang"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "shamir"
app.Usage = "command line tool for easy Shamir Secret Sharing"
app.Commands = []cli.Command{
{
Name: "share",
Flags: []cli.Flag{
cli.IntFlag{
Name: "minimum, m",
},
cli.IntFlag{
Name: "total, t",
},
cli.StringFlag{
Name: "secret, s",
},
},
Action: func(c *cli.Context) error {
shares, err := sssa.Create(c.Int("minimum"), c.Int("total"), c.String("secret"))
if err != nil {
return err
}
fmt.Println(strings.Join(shares, "\n"))
return nil
},
},
{
Name: "unite",
Usage: "shares read from stdin, one per line",
Action: func(c *cli.Context) error {
stdinBytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
stdinText := strings.TrimSpace(string(stdinBytes))
shares := make([]string, 0)
for _, line := range strings.Split(stdinText, "\n") {
shares = append(shares, line)
}
secret, err := sssa.Combine(shares)
if err != nil {
return err
}
fmt.Println(secret)
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment