示例#1
0
func Test_Question5_RepeatingXor(t *testing.T) {
	const key, in, out = "ICE", "Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal", "0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f"

	x := RepeatXor([]byte(key), []byte(in))

	if encoding.HexEncodeToString(x) != out {
		t.Errorf("RepeatXor(%#v, %#v) = %#v want %#v", key, in, encoding.HexEncodeToString(x), out)
	}
}
示例#2
0
func Test_Question1_Base64ToHex(t *testing.T) {
	const in, out = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t", "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"

	if x := encoding.HexEncodeToString(encoding.Base64DecodeString(in)); x != out {
		t.Errorf("HexEncodeToString(Base64DecodeString(%v)) = %v, want %v", in, x, out)
	}
}
示例#3
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)
	}
}