Last active
January 8, 2019 19:52
-
-
Save zaltoprofen/1eb9f27e774905c5822d6432fcd0865f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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