Exemplo n.º 1
0
func findBestCypher(bytes []byte) byte {
	var best Candidate
	for i := 0; i < 256; i++ {
		cypher := byte(i)
		decoded := matasano.FixedXorWithSingleByteMask(bytes, cypher)
		phrase := string(decoded)
		englishness := getLetterDensity(phrase)
		if best.englishness < englishness {
			best = Candidate{englishness, phrase, cypher, 0}
		}
	}
	return best.cypher
}
Exemplo n.º 2
0
func findCandidate(c chan<- Candidate, bytes []byte, line int) {
	var best Candidate
	for i := 0; i < 256; i++ {
		cypher := byte(i)
		decoded := matasano.FixedXorWithSingleByteMask(bytes, cypher)
		phrase := string(decoded)
		englishness := 1 / stdDevFromCharFrequencies(phrase)
		if best.englishness < englishness {
			best = Candidate{englishness, phrase, cypher, line}
		}
	}
	c <- best
}