Alan and his team are at the Beer Hut, and in a gloomy mood as they realise Alan's machine will never be able to complete all the combinations before time runs out and the code is reset. Hugh starts to flirt with a friend of Joan's, who tells Alan that she is in love with a German who writes code, but fears he has another love as he always starts his message with CILLY - even though they are meant to choose 5 random letters each time.
Alan drops his beer and races back to the code room, with the others trying their best to follow. He has found a breakthrough - they just need a small sample to work through, and the Germans end their weather reports with Heil Hitler. They just need to crack those messages, to solve the code for that day. Using his idea, they get to work, and soon map out the positions of all the German warships in the Atlantic Ocean.
They also find that warships are closing in on a civilian transporter - carrying the brothers of one of the team back to Britain. Peter desperately wants Alan to intervene - but they know that to do so now would alert the Germans that they have broken the code.
Alan takes his findings to Menzies, and suggests a statistical analysis to stop the Germans a small number of times, to slowly win the war and keep their code-breaking secret.
Back in the office, Peter (whose brothers died) starts to bully Alan again and knocks over his books - where Alan finds a Bible used by the other code-breaker, John, with text highlighted that they know was used by the Russian spy. Alan confronts John - but he retaliates and says that he will tell the authorities that Alan is a homosexual.
That night, Alan goes to Joan's flat but finds Menzies instead - Joan has been framed as the Russian spy, even though they know all about John, and have been keeping tabs on him for years. Alan later finds Joan and the only way he can get her to leave, is to tell her he never loved her and was just using her.
Soon enough it's VE Day, and the team are told to burn all their evidence, and keep a low profile in case Enigma resurfaces again.
We jump back to the first scene, and Alan was convicted. Joan visits him at his flat, where we learn that with a choice of prison or hormone supplements, he chose the hormones and has been trying to carry on with work on Christopher, his machine, but the treatment is destroying his ability and he struggles even with a simple crossword. Joan is happily married now, and thanks him for the great service he has done for his country.
As it ends, we learn that Alan killed himself after a year of hormone supplements. In 2013 the Queen granted Alan a posthumous pardon in recognition for his achievements.
Experts believe that breaking Enigma shortened the war by at least 2 years, saving millions of lives. Alan's work with machines was ground-breaking, and inspired what we now know as "computers".