-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform_test.go
79 lines (62 loc) · 1.51 KB
/
transform_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
package cryptanalysis
import (
"bytes"
"testing"
)
func TestChunk(t *testing.T) {
data := []byte("TESTDATA")
res3 := [][]byte{}
res3 = append(res3, []byte("TES"))
res3 = append(res3, []byte("TDA"))
res3 = append(res3, []byte("TA\x01"))
res4 := [][]byte{}
res4 = append(res4, []byte("TEST"))
res4 = append(res4, []byte("DATA"))
res4 = append(res4, []byte("\x04\x04\x04\x04"))
c3 := Chunk(PadPkcs7(data, 9), 3)
c4 := Chunk(PadPkcs7(data, 12), 4)
for i, _ := range res3 {
if bytes.Compare(res3[i], c3[i]) != 0 {
t.Error("Expected", res3, "got", c3)
}
}
for i, _ := range res4 {
if bytes.Compare(res4[i], c4[i]) != 0 {
t.Error("Expected", res4, "got", c4)
}
}
}
func TestTranspose(t *testing.T) {
m1 := [][]byte{}
m1 = append(m1, []byte{1, 2})
m1 = append(m1, []byte{3, 4})
m2 := [][]byte{}
m2 = append(m2, []byte{1, 3})
m2 = append(m2, []byte{2, 4})
m3 := Transpose(m1)
for i, _ := range m2 {
if bytes.Compare(m2[i], m3[i]) != 0 {
t.Error("Expected", m2, "got", m3)
}
}
}
func TestPadPkcs7(t *testing.T) {
str := []byte("YELLOW SUBMARINE")
pad := []byte("YELLOW SUBMARINE\x04\x04\x04\x04")
pkcs := PadPkcs7(str, 20)
if bytes.Compare(pkcs, pad) != 0 {
t.Error("Expected", pad, "got", pkcs)
}
}
func TestCaesarShift(t *testing.T) {
str := "YellowSubmarine"
shifted := "LryybjFhoznevar"
test := CaesarShift(str, 13)
if test != shifted {
t.Error("Expected", shifted, "got", test)
}
test = CaesarShift(shifted, 13)
if test != str {
t.Error("Expected", str, "got", test)
}
}