Excerpts from private letters written by Alan Turing have offered a glimpse into the anguish and confusion that the famed gay codebreaker endured in his final days.

Turing’s brilliant mind was instrumental in both the invention of the modern computer and ending the Second World War by cracking the Nazi’s Enigma Code, but his life ended in tragedy when, it is suspected, he took his own life at age 41 after being arrested and chemically castrated for engaging in homosexual acts in the 1950s.

The letters were originally penned to Nick Furbank, a literary scholar and friend of Turing who died last year, but are now in the possession of Turing’s nephew Sir Dermot Turing. The correspondence is set to be included in an upcoming book, ‘Prof: Alan Turing Decoded.’

The excerpts show Turing’s struggle with the pressure places on him to ‘turn straight’ and his relationship with his mother who tried to support her son though his darkest days.

Turing wrote: “I have had a dream indicating rather clearly that I am on the way to being hetero, though I don’t accept it with much enthusiasm either awake or in the dreams,” Turing wrote in one letter about his life after the punishment that was supposed to “cure” his homosexuality.

“Mother has been staying here, and we seem to be getting on a good deal better. I have been subjecting her to a good deal of sexual enlightenment and she seems to have stood up to it very well. There was a rather absurd dream I had the other night in which I asked mother’s opinion about going to bed with some men and she said: ‘Oh very well, but don’t go walking about the place naked like you did before.’

When discussing an upcoming trip abroad, Turing’s sexual confusion was again evident.

“I expect to lie in the sun, talk French and modern Greek, and make love, though the sex and nationality… has yet to be decided: in fact it is quite possible that this item will be altogether omitted,” he wrote. “I want a permanent relationship and I might feel inclined to reject anything which of its nature could not be permanent.”

Sir Dermot Turing described his uncle’s letters as a “very interesting” insight into a particularly complex individual who in many respects was as difficult to decipher as the complex codes that he spent his life trying to crack.

“At the same time that he was having his psychotherapy, and… his hormones taken out… [the correspondence] indicates that he was in a good deal of a turmoil, which… has historically been what everyone had assumed, but now is confirmed,” Sir Dermot said.

The younger Turing was also intrigued by the insight offered into mother son relationship depicted in the letters.

“There has been a tendency to ‘soppify’ this relationship, assuming that everything was tender and lovely whereas I am absolutely sure it was more complex and with some dark shades. This correspondence confirms that.”

Alan Turing’s life was recently depicted in the popular 2014 film The Imitation Game after Queen Elizabeth II officially pardoned Turing’s conviction in 2013.