Keira Knightley is in talks to star opposite Benedict Cumberbatch in the biopic based on the life of Enigma codebreaker Alan Turing.

Sherlock star Benedict is attached to play the British mathematician, who helped crack the German Enigma code during the final years of World War II, in Imitation Game, based on the book Alan Turing: The Enigma.

After the war Turing was prosecuted by British authorities for having a sexual relationship with another man, and forced to undergo "chemical castration" instead of being sent to prison for his sexuality. The genius mathematician and computer scientist committed suicide by eating an apple laced with cyanide and it is claimed Steve Jobs named his company Apple as a tribute to him.

Now, according to The Hollywood Reporter, Keira is in talks to play a woman from a very conservative background who formed a complicated relationship with Turing and was a close friend to him up until his death.

Norwegian filmmaker Morten Tyldum, of Headhunters fame, will direct the indie drama on a budget of 15 million dollars.

Turing appeared to be written out of the 2001 film Enigma, about the Bletchley Park codebreakers, despite being the leading figure at the World War II centre.

Dougray Scott's character Jerico seemed to resemble Turing, but he was heterosexual and had an affair with Kate Winslet's character.

The new film was previously in production at Warner Bros with Leonardo DiCaprio linked to the role of Turing and director Ron Howard was said to be interested in the film.