-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxor_test.go
117 lines (100 loc) · 3.48 KB
/
xor_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
package xcrypto
import (
"bytes"
"testing"
"github.com/fufuok/utils/assert"
)
func TestXOREnStringHex(t *testing.T) {
actual := XOREnStringHex("1", []byte("1"))
assert.Equal(t, "51", actual)
res := XOREnStringHex("", tmpK)
assert.Equal(t, "", XORDeStringHex(res, tmpK))
res = XOREnStringHex(tmpS, tmpK)
assert.Equal(t, tmpS, XORDeStringHex(res, tmpK))
}
func TestXOREnStringB64(t *testing.T) {
actual := XOREnStringB64("1", []byte("1"))
assert.Equal(t, "UQ==", actual)
res := XOREnStringB64("", tmpK)
assert.Equal(t, "", XORDeStringB64(res, tmpK))
res = XOREnStringB64(tmpS, tmpK)
assert.Equal(t, tmpS, XORDeStringB64(res, tmpK))
}
func TestXOREnStringB58(t *testing.T) {
actual := XOREnStringB58("1", []byte("1"))
assert.Equal(t, "2Q", actual)
res := XOREnStringB58("", tmpK)
assert.Equal(t, "", XORDeStringB58(res, tmpK))
res = XOREnStringB58(tmpS, tmpK)
assert.Equal(t, tmpS, XORDeStringB58(res, tmpK))
}
func BenchmarkEnDeXOR(b *testing.B) {
src := bytes.Repeat(tmpB, 10)
key := tmpK
// res := XOR(src, key)
// fmt.Println(string(XOR(res, key)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
res := XOR(src, key)
XOR(res, key)
}
}
func BenchmarkEnDeAesCBC(b *testing.B) {
src := bytes.Repeat(tmpB, 10)
key := tmpK
// res := AesCBCEncrypt(false, src, key)
// fmt.Println(string(AesCBCDecrypt(false, res, key)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
res := AesCBCEncrypt(false, src, key)
AesCBCDecrypt(false, res, key)
}
}
func BenchmarkEnDeGCM(b *testing.B) {
src := bytes.Repeat(tmpB, 10)
key := tmpK
// res, nonce := AesGCMEncrypt(src, key)
// fmt.Println(string(AesGCMDecrypt(res, key, nonce)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
res, nonce := AesGCMEncrypt(src, key)
AesGCMDecrypt(res, key, nonce)
}
}
func BenchmarkEnDeDesCBC(b *testing.B) {
src := bytes.Repeat(tmpB, 10)
key := []byte("12345678")
// res := DesCBCEncrypt(false, src, key)
// fmt.Println(string(DesCBCDecrypt(false, res, key)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
res := DesCBCEncrypt(false, src, key)
DesCBCDecrypt(false, res, key)
}
}
func BenchmarkEnDeAesCBCB64(b *testing.B) {
src := bytes.Repeat(tmpB, 10)
key := tmpK
// res := AesCBCEnB64(src, key)
// fmt.Println(string(AesCBCDeB64(res, key)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
res := AesCBCEnB64(src, key)
AesCBCDeB64(res, key)
}
}
// BenchmarkEnDeXOR-12 209040 5701 ns/op 3200 B/op 4 allocs/op
// BenchmarkEnDeXOR-12 211089 5716 ns/op 3200 B/op 4 allocs/op
// BenchmarkEnDeAesCBC-12 601584 1933 ns/op 2928 B/op 18 allocs/op
// BenchmarkEnDeAesCBC-12 601578 1932 ns/op 2928 B/op 18 allocs/op
// BenchmarkEnDeGCM-12 925539 1259 ns/op 2448 B/op 13 allocs/op
// BenchmarkEnDeGCM-12 925489 1261 ns/op 2448 B/op 13 allocs/op
// BenchmarkEnDeDesCBC-12 72048 16426 ns/op 2248 B/op 12 allocs/op
// BenchmarkEnDeDesCBC-12 73365 16461 ns/op 2248 B/op 12 allocs/op
// BenchmarkEnDeAesCBCB64-12 376006 3225 ns/op 5104 B/op 22 allocs/op
// BenchmarkEnDeAesCBCB64-12 353877 3219 ns/op 5104 B/op 22 allocs/op