I'm writing a python script to crack a playfair cipher, with only the ciphertext. First i generate about 30-100 decryption keys and run them on the ciphertext, ranking each one on it's digraph frequencies. To the next 'generation'/iteration I copy the ones with the best score. Then they are mutated (letters swapped places in the 5x5 grid) and re-add to the next iteration, which is ranked again, and so on.
I've noticed that the script often finds a local maximum - a key giving a similar distribution, yet not the real deal. I think a solution to the problem would be to introduce more variation to the population of keys (by the end of the script, all of them are almost the same).
I tried to implement it by adding to each generation a couple totally random keys but they get eliminated almost immediately. What would be a better way of doing it? I've also thought of tactics like simulated annealing, but have no idea how much help they would be.
EDIT: Sample ciphertext as requested (key: playfair example)
['p', 'l', 'a', 'y', 'f']
['i', 'r', 'e', 'x', 'm']
['b', 'c', 'd', 'g', 'h']
['k', 'n', 'o', 'q', 's']
['t', 'u', 'v', 'w', 'z']
as el ir ul vi ne uz qk dm kz qe ca qe tb qc pv zb md nv om lo gv qo od er qc zg pv vk ov or iw zg ro nz ge ro af yp qe zi lo rk pr ad xl dl ix cl qr rk dq vu sa zb xv qe ho dm dn ok eb xe do bm iz kd de as kv ef kc rd lv om dm vy km ur et xe aq zb xe tx om rt gh rk hc fg mk py dr qo af zs xv nv ac df ad dl yr do bm ef pm zs lo ce yl ai ca nv ca fy wi dm ov ne tx zb bm kn ul bn ar km uz fo ka ro do gp lo kv dm ml qe zi lo rk pr ad xl tx zb le nv oc py dr lo ca le dx xa mo pr oi yp en dy oc dk zb as kv ix ol pr dr oq pb dr gb eo ak vg xe do df re zb pv nl cr do ya an ad iu dm re dm eo qm dm am pu ad xl nl er nv kz qn oq yg df pb uz fo ya ay dk vu lo gd ex ip ya bp up xv yf nv vk pz dm vq vo vk pr kz ro
You mutate your generation, but you do not recombine it, if I read your question correctly. Maybe you can go about it like this:
Recombination could look like this: