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 }
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 }