-
Notifications
You must be signed in to change notification settings - Fork 0
/
break_test.go
35 lines (27 loc) · 814 Bytes
/
break_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
package cryptanalysis
import (
"bytes"
"testing"
)
func TestBreakSingleByteXor(t *testing.T) {
enc_key := byte(133)
data := []byte("Testing single byte xor breakage.")
cipher := []byte{209, 224, 246, 241, 236, 235, 226, 165, 246, 236, 235,
226, 233, 224, 165, 231, 252, 241, 224, 165, 253, 234, 247, 165,
231, 247, 224, 228, 238, 228, 226, 224, 171}
_, dec_key, plain := BreakSingleByteXor(cipher, ChiAlphaSpace)
if dec_key != enc_key {
t.Error("Expected", enc_key, "got", dec_key)
}
if bytes.Compare(data, []byte(plain)) != 0 {
t.Error("Expected", data, "got", plain)
}
}
func TestBreakCaesarShift(t *testing.T) {
str := "YellowSubmarine"
shifted := "LryybjFhoznevar"
_, _, plain := BreakCaesarShift(shifted, ChiAlpha)
if plain != str {
t.Error("Expected", str, "got", plain)
}
}