Пример #1
0
func Test_Question2_fixedXor(t *testing.T) {
	const in_a, in_b, out = "1c0111001f010100061a024b53535009181c", "686974207468652062756c6c277320657965", "746865206b696420646f6e277420706c6179"
	x := FixedXor(encoding.HexDecodeString(in_a), encoding.HexDecodeString(in_b))

	if encoding.HexEncodeToString(x) != out {
		t.Errorf("FixedXor(%v, %v) = %v, want %v", in_a, in_b, x, out)
	}
}
Пример #2
0
func Test_Question1_HexToBase64(t *testing.T) {
	const in, out = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d", "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"

	if x := encoding.Base64EncodeToString(encoding.HexDecodeString(in)); x != out {
		t.Errorf("Base64EncodeToString(HexDecodeString(%v)) = %v, want %v", in, x, out)
	}
}
Пример #3
0
func Test_Question3_DecryptSingleXor(t *testing.T) {
	const in, out_result, out_key = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736", "Cooking MC's like a pound of bacon", byte(88)

	result, key, _ := DecryptSingleXor(encoding.HexDecodeString(in))

	if string(result) != out_result || key != out_key {
		t.Errorf("DecryptSingleXor = %#v, %#v want %#v, %#v", string(result), key, out_result, out_key)
	}
}