I'm having some problem in the Matasano challenge number 6 (the breaking repeating key-XOR one)
I'm using Go and for the other challenges I have used a map with the char
as key and the frequency as value
func findKeyElement(ct []byte) ([]byte, byte) {
ot := map[string]float64{"e": 13, "t": 9.1, "a": 8.2, "o": 7.5, "i": 7, "n": 6.7, "s": 6.3, "h": 6.1, "r": 6, "d": 4.3,
"l": 4, "u": 2.8, "c": 2.8, "m": 2.4, "w": 2.4}
TopScore, newScore := -1.0, 0.0
var text, decrText []byte
var key byte
for i := 0; i < 255; i++ {
text = singleByteXor(ct, byte(i))
newScore = calculateScore(text, ot)
if newScore > TopScore {
TopScore = newScore
decrText = text
key = byte(i)
}
}
return decrText, key
}
func calculateScore(text []byte, ot map[string]float64) float64 {
score := 0.0
for i := range text {
score += ot[string(text[i])]
}
return score
}
and I'm having good results in all the previous challenges
In this one you have to brake the ciphertext into KeySize
chunks and break them grouping by column (since the char of the key is the same, treating it like a single byte xor)
Using the same technique I got the following key
Ter(inator X bring the noise
So I basically got it, except for the first m
. Probably it is due to the fact that the associated column has a lot of special chars like " "
or " ' "
, in fact tuning the map frequency adding them I get the correct key. Is there a way to recognize it and avoid tuning manually the occurrences map?
Thank in advance