# Recover all keys on differential cryptanalysis

I am practically implementing differential cryptanalysis on a cipher from the book "the block cipher companion" .

I am successful to get the last key $$k_5$$. Just to say some words about the implementation:

1. I search for a good differential, calculate the probability and generate a list of input pairs which satisfy my input difference.

2. I let the pairs flow through the cipher (with the unknown keys) and then I guess the key bits of the sbox in the last round who are involved in my expected differential.

3. Now I decrypt with my guessed key, undo the sbox and generate the difference of the pair. If it satisfys my expected value, I count it as a hit. The key with the highest counter is probably the right one. So far so good. I can recover $$k_5$$.

However I can not get it work with the $$k_4$$.

I do the following: Search for a good differential, calculate the probability and generate the list with pairs which satisfy my input difference. I let them flow through the cipher and decrypt the last round with my recovered $$k_5$$. Then I undo the sbox and apply my guessed $$k_4$$ undo the permutation and undo the next sbox. Then I generate the difference and compare to the expected...

But this does not work. Is there a general mistake in my doing here?