Skip to content

Instantly share code, notes, and snippets.

@zaltoprofen
Last active January 8, 2019 19:52
Show Gist options
  • Save zaltoprofen/1eb9f27e774905c5822d6432fcd0865f to your computer and use it in GitHub Desktop.
Save zaltoprofen/1eb9f27e774905c5822d6432fcd0865f to your computer and use it in GitHub Desktop.
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
func main() {
p, _ := rand.Prime(rand.Reader, 256)
g, _ := rand.Int(rand.Reader, p)
a, _ := rand.Int(rand.Reader, p.Sub(p, big.NewInt(1)))
A := g.Exp(g, a, p)
// Alice - send(g, p, A) -> Bob
b, _ := rand.Int(rand.Reader, p.Sub(p, big.NewInt(1)))
B := g.Exp(g, b, p)
// Bob - send(g, p, B) -> Bob
// Bob side
Kb := A.Exp(A, b, p)
// Alice side
Ka := B.Exp(B, a, p)
fmt.Println("Ka:", Ka.Text(16))
fmt.Println("Kb:", Kb.Text(16))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment