-
Notifications
You must be signed in to change notification settings - Fork 2
/
roxor_test.go
38 lines (33 loc) · 989 Bytes
/
roxor_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
package main
import "testing"
var NoMatch = []Match{}
var Needle = []byte("needle")
var attackCipherTests = []struct {
ciphertext []byte
crib []byte
matches []Match
}{
{[]byte{}, []byte{}, NoMatch},
{[]byte("haystack"), Needle, NoMatch},
{[]byte("needle in haystack"), Needle, []Match{{0, 0}}},
{[]byte("a needle, another needle"), Needle, []Match{{2, 0}, {18, 0}}},
{[]byte{0x23, 0x62, 0x2c, 0x27, 0x27, 0x26, 0x2e, 0x27,
0x6e, 0x62, 0x23, 0x2c, 0x2d, 0x36, 0x2a, 0x27,
0x30, 0x62, 0x2c, 0x27, 0x27, 0x26, 0x2e, 0x27},
Needle, []Match{{2, 0x42}, {18, 0x42}}},
}
func TestAttackCipher(t *testing.T) {
for _, test := range attackCipherTests {
got := attackCipher(test.ciphertext, test.crib, nil)
want := test.matches
if len(got) != len(want) {
t.Errorf("expected length %d, got %d", len(want), len(got))
} else {
for i, m := range got {
if m != want[i] {
t.Errorf("expected match #%d to be %v, got %v", i, want[i], m)
}
}
}
}
}