# Hamming distance in xor decryption

I've been working on cryptopals 1.6, breaking xor and have got it working. I found this answer that explains why hamming distance works and I think after some thinking I believe I'm starting to understand it.

One thing that I really stumbled on was keysize estimation, step 3. I finally found a writeup that did something like this

fn score_keysize(keysize, bytes) {
let block1 = bytes.getblock(size=keysize)
let block2 = bytes.getblock(offset=keysize, size=keysize)
let block3 = bytes.getblock(offset=keysize*2, size=keysize)
let block4 = bytes.getblock(offset=keysize*3, size=keysize)
let hamming = hamming(a,b) + hamming(b,c) + hamming(c,d)
return hamming / 3
}


And that works, I tried a variant of that but didn't get even nearly as good results. All my attempts almost, with some variance, got a lower score the larger the key got, this included.

fn score_keysize(keysize, bytes) {
let block1 = bytes.getblock(size=keysize)
let block2 = bytes.getblock(offset=keysize, size=keysize)
let block3 = bytes.getblock(offset=keysize*2, size=keysize)
let block4 = bytes.getblock(offset=keysize*3, size=keysize)
let hamming = hamming(a,b) + hamming(c,d)
return hamming / 2
}


Could someone explain why that's so much worse? Or is it dependent on the text? How do I avoid spending 3 days on something like this again?