generated from UofSC-Fall-2022-Math-587-001/homework11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl_test.go
137 lines (131 loc) · 2.67 KB
/
impl_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package hw12
import (
"github.com/UofSC-Fall-2022-Math-587-001/homework12/ec"
"testing"
"fmt"
)
func Test1(t *testing.T) {
A := 100
B := 101
N := 223
X := 170
Y := 169
s := 50
d := 40
C, err := ec.MakeCurve(A,B)
if err != nil {
t.Errorf("The discriminant should not be 0.\n")
}
p := &ec.FinitePoint{X:X,Y:Y}
fmt.Printf("P = %s\n",p)
ord := ec.Order(C,N,p)
fmt.Printf("The order of %s is %d\n",p,ord)
D := Data{N,C,p,ord}
K := PrivateKey{D,s}
V := K.PublicKey()
signed := K.Sign(d)
checked := V.Verify(d,signed)
if checked != nil {
t.Errorf("The signature cannot be verified\n")
}
}
func Test2(t *testing.T) {
A := 1
B := 1
N := 1627
X := 1502
Y := 219
s := 45
d := 31
C, err := ec.MakeCurve(A,B)
if err != nil {
t.Errorf("The discriminant should not be 0.\n")
}
p := &ec.FinitePoint{X:X,Y:Y}
fmt.Printf("P = %s\n",p)
ord := ec.Order(C,N,p)
fmt.Printf("The order of %s is %d\n",p,ord)
D := Data{N,C,p,ord}
K := PrivateKey{D,s}
V := K.PublicKey()
signed := K.Sign(d)
checked := V.Verify(d,signed)
if checked != nil {
t.Errorf("The signature cannot be verified\n")
}
}
func Test3(t *testing.T) {
A := 200
B := 300
N := 7919
X := 7893
Y := 6660
s := 1541
d := 1776
C, err := ec.MakeCurve(A,B)
if err != nil {
t.Errorf("The discriminant should not be 0.\n")
}
p := &ec.FinitePoint{X:X,Y:Y}
fmt.Printf("P = %s\n",p)
ord := ec.Order(C,N,p)
fmt.Printf("The order of %s is %d\n",p,ord)
D := Data{N,C,p,ord}
K := PrivateKey{D,s}
V := K.PublicKey()
signed := K.Sign(d)
checked := V.Verify(d,signed)
if checked != nil {
t.Errorf("The signature cannot be verified\n")
}
}
func Test4(t *testing.T) {
A := 200
B := 300
N := 7919
X := 7893
Y := 6660
s := 1541
d := 1776
C, err := ec.MakeCurve(A,B)
if err != nil {
t.Errorf("The discriminant should not be 0.\n")
}
p := &ec.FinitePoint{X:X,Y:Y}
fmt.Printf("P = %s\n",p)
ord := ec.Order(C,N,p)
fmt.Printf("The order of %s is %d\n",p,ord)
D := Data{N,C,p,ord}
K := PrivateKey{D,s}
V := K.PublicKey()
signed := Signature{440,440}
checked := V.Verify(d,signed)
if checked == nil {
t.Errorf("The signature should not be verified\n")
}
}
func Test5(t *testing.T) {
A := 1
B := 1
N := 1627
X := 1502
Y := 219
s := 45
d := 31
C, err := ec.MakeCurve(A,B)
if err != nil {
t.Errorf("The discriminant should not be 0.\n")
}
p := &ec.FinitePoint{X:X,Y:Y}
fmt.Printf("P = %s\n",p)
ord := ec.Order(C,N,p)
fmt.Printf("The order of %s is %d\n",p,ord)
D := Data{N,C,p,ord}
K := PrivateKey{D,s}
V := K.PublicKey()
signed := Signature{234,444}
checked := V.Verify(d,signed)
if checked == nil {
t.Errorf("The signature should not be verified\n")
}
}