Queen Elizabeth pardoned mathematician and computer pioneer Alan Turin, who saved many lives by cracking Nazi Germany’s “unbreakable code” but took his own in 1954 after a criminal conviction for homosexuality.

Turin, whose electromechanical machine broke the “Enigma” code German U-boats used, was credited with helping the Allies win World War II.

Turing was an “exceptional man with a brilliant mind,” Grayling said in a statement.

"His brilliance was put into practice at Bletchley Park during the Second World War where he was pivotal to breaking the 'Enigma' code, helping to end the war and save thousands of lives," he continued.

Turing lost his job and was chemically castrated after being convicted of gross indecency in 1952 for homosexual sex, which was was illegal in Britain until 1967.

"The persecution of this great British scientist over his sexuality was tragic and I'm delighted that we can now focus solely on celebrating his legacy," scientist Paul Nurse, president of the Royal Society, told Reuters.