예제 #1
0
파일: xor_test.go 프로젝트: bonnefoa/crypto
func TestSeekXor(t *testing.T) {
	src := hexa.HexaToBytes("1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736")
	candidates := SeekXor(src)
	for i := 0; i < 5; i++ {
		t.Logf("Candidate %d is %q\n", candidates[i])
	}
	assert.AssertEquals(t, string(candidates[0].Decrypted), "Cooking MC's like a pound of bacon")
}
예제 #2
0
파일: xor.go 프로젝트: bonnefoa/crypto
func SeekXorInFile(filename string) XorCandidates {
	content, _ := ioutil.ReadFile(filename)
	lines := strings.Split(string(content), "\n")
	xorCandidates := make(XorCandidates, 0)
	for _, line := range lines {
		for _, xorCandidate := range SeekXor(hexa.HexaToBytes(line)) {
			xorCandidates = append(xorCandidates, xorCandidate)
		}
	}
	sort.Sort(ByScore{xorCandidates})
	return xorCandidates
}
예제 #3
0
func TestBase64Encode(t *testing.T) {
	src := hexa.HexaToBytes("49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d")
	expected := "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
	assert.AssertEquals(t, Base64ToString(Base64Encode(src)), expected)
}
예제 #4
0
파일: xor_test.go 프로젝트: bonnefoa/crypto
func TestXor(t *testing.T) {
	src := hexa.HexaToBytes("1c0111001f010100061a024b53535009181c")
	xor := hexa.HexaToBytes("686974207468652062756c6c277320657965")
	expected := hexa.HexaToBytes("746865206b696420646f6e277420706c6179")
	assert.AssertBytesEquals(t, Xor(src, xor), expected)
}