Sherlock star Benedict Cumberbatch is set to play the gay maths genius Alan Turing in the new film The Imitation Game.

The British actor will step into the shoes of the man that helped win World War 2 and was later prosecuted for his homosexuality in the forthcoming biopic.

Based on a script by first-time screenwriter Graham Moore, it was bought by Warner Bros in 2011 for a seven-figure sum.

Hollywood star Leonardo DiCaprio was set to play the mathematician, but when he said he was no longer interested the studio dropped the film.

Turing was a wartime hero credited with cracking the German Enigma code, but his life was destroyed by the period’s anti-homosexuality laws.

He was arrested seven years after the war ended, forced to undergo reparative therapy to try to cure his sexuality, and accepted chemical castration as an alternative to prison.

Turing is believed to have committed suicide two years later; after it was found he died from cyanide poisoning.

After an internet campaign, Prime Minister Gordon Brown formally apologized on the behalf of the British government in 2009. However, he was not given an official pardon.

Since starring in several British dramas, Cumberbatch is in Hollywood securing roles as the main villain in the new Star Trek film as well as the dragon Smaug in Peter Jackson’s Hobbit trilogy.

He will also play Julian Assange in The Fifth Estate, a film about the WikiLeaks founder’s early life.