Example #1
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)
	}
}
Example #2
0
func Test_Question12_AesCBCDecrypt(t *testing.T) {
	const in = "Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK"
	const out = "Rollin' in my 5.0\nWith my rag-top down so my hair can blow\nThe girlies on standby waving just to say hi\nDid you stop? No, I just drove by\n"

	data := encoding.Base64DecodeString(in)

	oracle := CreateOracle(data)

	result := CrackAesEcb(oracle)

	if string(result) != out {
		t.Errorf("CrackAesEcb(data) = %#v, expected %#v", string(result), out)
	}
}
Example #3
0
func Test_Question6_DecryptXor(t *testing.T) {
	const in, out = "gistfile2.txt", "Terminator X: Bring the noise"
	fs, _ := os.Open(in)
	defer fs.Close()

	data, _ := ioutil.ReadAll(fs)
	data = encoding.Base64DecodeString(string(data))

	_, key := DecryptXor(data, 0.05)

	if string(key) != out {
		t.Errorf("DecryptXor(%#v, 4, 10) = %#v want %#v", in, string(key), out)
	}
}
Example #4
0
func Test_Question10_AesCBCDecrypt(t *testing.T) {
	const in, key, out = "gistfile1.txt", "YELLOW SUBMARINE", "I'm back and I'm ringin' the bell"

	fs, _ := os.Open(in)
	defer fs.Close()

	text, _ := ioutil.ReadAll(fs)
	data := encoding.Base64DecodeString(string(text))

	result := AesCBCDecrypt([]byte(key), make([]byte, 16), data)

	if !strings.HasPrefix(string(result), out) {
		t.Errorf("AesCBCDecrypt failed")
	}
}
Example #5
0
func Test_Question7_DecryptAesEcb(t *testing.T) {
	const in, out = "gistfile3.txt", "I'm back and I'm ringin' the bell"

	fs, _ := os.Open(in)
	defer fs.Close()

	data, _ := ioutil.ReadAll(fs)
	data = encoding.Base64DecodeString(string(data))

	result := DecryptAes(data, []byte("YELLOW SUBMARINE"))

	if !strings.HasPrefix(string(result), "I'm back and I'm ringin' the bell") {
		t.Errorf("DecryptAes failed")
	}
}