-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblowfish_test.go
More file actions
86 lines (63 loc) · 1.85 KB
/
Copy pathblowfish_test.go
File metadata and controls
86 lines (63 loc) · 1.85 KB
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
package blowfish
import (
"encoding/binary"
"reflect"
"testing"
)
func validateTestString(t *testing.T, got, want string) {
if got != want {
t.Errorf("expected '%s' but got '%s'", want, got)
}
}
func validateTestByte(t *testing.T, got, want []byte) {
if !reflect.DeepEqual(got, want) {
t.Errorf("expected '%s' but got '%s'", want, got)
}
}
func TestUtils(t *testing.T) {
t.Run("Split Function (even)", func(t *testing.T) {
ogText := []byte("abcdefgh")
xL, xR := SplitText(ogText)
expectedL := []byte("abcd")
expectedR := []byte("efgh")
if string(expectedL) != string(xL) {
t.Errorf("expected '%s' but got '%s'", expectedL, xL)
}
if string(expectedR) != string(xR) {
t.Errorf("expected '%s' but got '%s'", expectedR, xR)
}
})
t.Run("Split Function (odd)", func(t *testing.T) {
ogText := []byte("abcdefg")
xL, xR := SplitText(ogText)
expectedL := []byte("abcd")
expectedR := []byte("efg")
if string(expectedL) != string(xL) {
t.Errorf("expected '%s' but got '%s'", expectedL, xL)
}
if string(expectedR) != string(xR) {
t.Errorf("expected '%s' but got '%s'", expectedR, xR)
}
})
t.Run("Merge Function", func(t *testing.T) {
expected := "abcdefgh"
ogText := []byte(expected)
xL, xR := SplitText(ogText)
got := string(MergeText(binary.BigEndian.Uint32(xL), binary.BigEndian.Uint32(xR)))
validateTestString(t, got, expected)
})
}
func TestBlowfish(t *testing.T) {
t.Run("EncryptBlock", func(t *testing.T) {
ogText := []byte("abcdefgh")
cypheredText := EncryptBlock(ogText)
decypheredText := DecryptBlock(cypheredText)
validateTestByte(t, decypheredText, ogText)
})
t.Run("Encrypt Text (< 8)", func(t *testing.T) {
ogText := "Hoje falaremos sobre as plantas"
cypheredText := Encrypt(ogText)
decypheredText, _ := Decrypt(cypheredText)
validateTestString(t, decypheredText, ogText)
})
}