-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 825 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"github.com/LosFurina/DiffieHellman/utils"
)
func main() {
p, err := utils.GenerateLargePrime(2048)
if err != nil {
return
}
g := utils.FindPrimitiveRoot(p)
a, err := utils.GeneratePrivateKey(p)
if err != nil {
return
}
A := utils.GeneratePubKey(g, p, a)
fmt.Println("A is:", A)
b, err := utils.GeneratePrivateKey(p)
if err != nil {
return
}
B := utils.GeneratePubKey(g, p, b)
fmt.Println("B is:", B)
SharedKeyA := utils.GenerateSharedKey(A, p, b)
SharedKeyB := utils.GenerateSharedKey(B, p, a)
fmt.Println("Shared Key A:", SharedKeyA)
fmt.Println("Shared Key B:", SharedKeyB)
if SharedKeyA.Cmp(SharedKeyB) == 0 {
fmt.Println("Shared keys match. Secure connection established.")
} else {
fmt.Println("Shared keys do not match. Connection compromised.")
}
}