Alan Turing, the Enigma codebreaker who took his own life after being convicted of gross indecency under anti-homosexuality legislation, is to be given a posthumous pardon.

The government signalled on Friday that it is prepared to support a backbench bill that would pardon Turing, who died from cyanide poisoning at the age of 41 in 1954 after he was subjected to "chemical castration".

Lord Ahmad of Wimbledon, a government whip, told peers that the government would table the third reading of the Alan Turing (statutory pardon) bill at the end of October if no amendments are made. "If nobody tables an amendment to this bill, its supporters can be assured that it will have speedy passage to the House of Commons," Ahmad said.

The announcement marks a change of heart by the government, which declined last year to grant pardons to the 49,000 gay men, now dead, who were convicted under the 1885 Criminal Law Amendment Act. They include Oscar Wilde.

Ahmad told peers: "Alan Turing himself believed that homosexual activity would be made legal by a royal commission. In fact, appropriately, it was parliament which decriminalised the activity for which he was convicted. The government are very aware of the calls to pardon Turing, given his outstanding achievements, and have great sympathy with this objective … That is why the government believe it is right that parliament should be free to respond to this bill in whatever way its conscience dictates and in whatever way it so wills."

The government threw its weight behind the private member's bill, promoted by the Liberal Democrat peer Lord Sharkey, after a debate that featured a contribution from a peer who worked at Bletchley Park. Lady Trumpington told peers: "The block I worked in was devoted to German naval codes. Only once was I asked to deliver a paper to Alan Turing, so … I cannot claim that I knew him. However, I am certain that but for his work we would have lost the war through starvation."

Turing broke German ciphers using the bombe method, which allowed the code-breakers to crack the German Enigma code. His colleague Tommy Flowers built the Colossus computer. Ahmad described Turing as "one of the fathers, if not the father, of computer science".

Sharkey has campaigned for a pardon after being taught mathematics at Manchester University in the 1960s by Robin Gandy, Turing's only doctoral student, who became a close friend and was the executor of his will.

Sharkey said: "As I think everybody knows, he was convicted in 1952 of gross indecency and sentenced to chemical castration. He committed suicide two years later. The government know that Turing was a hero and a very great man. They acknowledge that he was cruelly treated. They must have seen the esteem in which he is held here and around the world."