generated from UofSC-Fall-2022-Math-587-001/homework3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw4_test.go
60 lines (50 loc) · 1.27 KB
/
hw4_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
package hillcipher
import (
"testing"
"reflect"
"github.com/UofSC-Fall-2022-Math-587-001/homework4/linearalg"
)
func Test1(t *testing.T) {
K1 := linearalg.Matrix2x2{1,3,2,2}
K2 := linearalg.Vector2{5,4}
H := HillCipherKey{K1,K2}
message := linearalg.Vector2{2,1}
got := H.encrypt(message,7)
want := linearalg.Vector2{3,3}
if !reflect.DeepEqual(got,want) {
t.Errorf("%d vs %d", got, want)
}
}
func Test2(t *testing.T) {
K1 := linearalg.Matrix2x2{1,3,2,2}
K2 := linearalg.Vector2{5,4}
H := HillCipherKey{K1,K2}
ciphertext := linearalg.Vector2{3,3}
got := H.decrypt(ciphertext,7)
want := linearalg.Vector2{2,1}
if !reflect.DeepEqual(got,want) {
t.Errorf("%d vs %d", got, want)
}
}
func Test3(t *testing.T) {
K1 := linearalg.Matrix2x2{2,1,3,3}
K2 := linearalg.Vector2{1,2}
H := HillCipherKey{K1,K2}
message := linearalg.Vector2{1,1}
got := H.encrypt(message,5)
want := linearalg.Vector2{4,3}
if !reflect.DeepEqual(got,want) {
t.Errorf("%d vs %d", got, want)
}
}
func Test4(t *testing.T) {
K1 := linearalg.Matrix2x2{2,1,3,3}
K2 := linearalg.Vector2{1,2}
H := HillCipherKey{K1,K2}
ciphertext := linearalg.Vector2{4,3}
got := H.decrypt(ciphertext,5)
want := linearalg.Vector2{1,1}
if !reflect.DeepEqual(got,want) {
t.Errorf("%d vs %d", got, want)
}
}