codebreaker-cp-7297655

A June 25, 2002, file picture shows a four-rotor Enigma machine, right, once used by the crews of German U-boats in the Second World War to send coded messages, which British mathematician Alan Turing was instrumental in breaking. ((Alex Dorgan Ross/Associated Press))

British Prime Minister Gordon Brown apologized Friday for the "inhumane" treatment of Second World War code-breaker Alan Turing, who was convicted of gross indecency for being homosexual at a time when it was illegal in Britain.

A mathematician, Turing helped crack Nazi Germany's Enigma communications code, which was a turning point in the war.

He was later convicted of gross indecency for having sex with a man and forcibly treated with female hormones to reduce his sex drive. Turing committed suicide in 1954 at the age of 41.

Turing was also known for his pioneering work on artificial intelligence and computer science, including his development of the "Turing Test" to measure whether a machine can think. One of the most prestigious honors in computing, the $250,000 US Turing Prize, is named for him.

"The debt of gratitude he is owed makes it all the more horrifying, therefore, that he was treated so inhumanely .… We're sorry, you deserved so much better," Brown said in his apology published Friday in the Daily Telegraph newspaper, as well as on the prime minister's office website.

The apology comes after an internet petition garnered more than 30,000 signatures supporting the move.

Gay rights campaigner Peter Tatchell said the apology was "most welcome and commendable."

With files from The Associated Press