A handwritten notebook by British World War II code-breaking genius Alan Turing, who was the subject of the 2014 Oscar-winning film The Imitation Game, brought more than $1 million at auction on Monday.

The 56-page manuscript 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 his complex mathematical and computer science notations and is believed to be the only extensive Turing manuscript known to exist, Bonhams auction house said.

The sale price was $1,025,000.

The Imitation Game, starring Benedict Cumberbatch in the role of Turing, won Best Adapted Screenplay at this year's Academy Awards.

Turing's notebook dates from 1942, when he and his team of cryptanalysts were at Britain's World War II code and cypher school Bletchley Park. In one entry, Turing wrote about a complex calculus notation.

"The Leibniz notation I find extremely difficult to understand in spite of it having been the one I understood the best once!" he wrote. "It certainly implies that some relation between x and y has been laid down eg, y=x2+3x."

The sale also included a working German Enigma enciphering machine. The three-rotor device, manufactured for the German military in July 1944, sold for $269,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 in a bid to eliminate his homosexuality as an alternative to imprisonment.

He died in 1954 of cyanide poisoning. His death 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.

A page from the hand-written notebook by Alan Turing, the World War II code-breaking genius. Image: Bebeto Matthews/Associated Press

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.

The notebook remained in Gandy's possession until he died in 1995, and Bonhams describes his entries as highly personal.

At the beginning of his journal, 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."

Turing scholar Andrew Hodges, in a statement through Bonhams, said the notebook sheds more light on how Turing "remained committed to free-thinking work in pure mathematics."

The Imitation Game, which also stars Keira Knightley, is based on Hodges' book "Alan Turing: The Enigma."

Bonhams said the buyer wished to remain anonymous. Part of the proceeds will be donated to charity.