A handwritten notebook by British Second World War code-breaking genius Alan Turing, whose story was portrayed in the 2014 Oscar-winning movie The Imitation Game, has been sold for more than $1 million.

Bonhams auctioned the 56-page manuscript - believed to be the only extensive Turing manuscript known to exist.

Part of the proceeds will be donated to charity.

The notebook was written at the time the mathematician and computer science pioneer was working to break the seemingly unbreakable Enigma codes used by the Germans throughout the war.

It contains Turing's complex mathematical and computer science notations.

The Imitation Game, starring Benedict Cumberbatch as Turing, won the Oscar for Best Adapted Screenplay.

The sale also includes a working German Enigma enciphering machine. The three-rotor device, manufactured for the German military in July 1944, is estimated to sell for $140,000 to $180,000.

Turing was prosecuted for being gay at a time when it was illegal in Britain. He was convicted of indecency in 1952 and agreed to undergo hormone treatment as an alternative to imprisonment to "cure" his homosexuality.

He died in 1954 of cyanide poisoning, which was ruled a suicide, although his family and friends believed it might have been accidental. The notebook was among the papers he left in his will to friend and fellow mathematician Robin Gandy.

Mr Gandy gave the papers to The Archive Centre at King's College in Cambridge in 1977. But he kept the notebook, using its blank pages for writing down his dreams at the request of his psychiatrist.

Bonham describes Mr Gandy's entries as highly personal; the notebook remained in his possession until he died in 1995.

At the beginning of his journal, Mr Gandy writes: "It seems a suitable disguise to write in between these notes of Alan's on notation, but possibly a little sinister; a dead father figure, some of whose thoughts I most completely inherited."

Bonhams said the seller wished to remain anonymous.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.