-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.go
47 lines (36 loc) · 1.4 KB
/
core_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
package main
import (
"encoding/hex"
"testing"
)
func TestHexDecodeToBase64(t *testing.T) {
result := HexDecodeToBase64("49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d")
if result != "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t" {
t.Error("innocorrect result", result)
}
}
func TestEncodeFixedXor(t *testing.T) {
input, _ := hex.DecodeString("1c0111001f010100061a024b53535009181c")
key, _ := hex.DecodeString("686974207468652062756c6c277320657965")
result := make([]byte, len(key))
EncodeFixedXor(result, input, key)
if hex.EncodeToString(result) != "746865206b696420646f6e277420706c6179" {
t.Error("innocorrect result", result)
}
}
func TestEncodeRepeatingXor(t *testing.T) {
inputByte := []byte("Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal")
inputKey := []byte("ICE")
result := EncodeRepeatingXor(inputByte, inputKey)
if hex.EncodeToString(result) != "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f" {
t.Error("innocorrect result", result)
}
}
func TestHammingDistance(t *testing.T) {
firstInputByte := []byte("this is a test")
secondInputByte := []byte("wokka wokka!!!")
result := HammingDistance(firstInputByte, secondInputByte)
if result != 37 {
t.Error("innocorrect result", result)
}
}