By Mary Milliken

TORONTO (Reuters) - The code-breaking machine that may have cut World War II by two years and saved millions of lives was invented by British mathematician Alan Turing, a prickly genius and unlikely war hero unknown to most of the world.

That might be because his work to crack Germany's Enigma code remained classified for decades. But also, Turing met a tragic end following the war, taking his own life at 41 after he was convicted for being homosexual and sentenced to chemical castration.

The star power of British actor Benedict Cumberbatch and his new film "The Imitation Game" could bring Turing's triumph and tragedy to a broad audience beyond Britain, where Queen Elizabeth recently pardoned the man who inspired the modern computer with his "Turing machine."

"The Imitation Game" is one of the most anticipated films at the Toronto Film Festival, where it will screen on Tuesday, and has earned praise and early awards buzz after distributor The Weinstein Co. gave a sneak peek at the Telluride Film Festival.

Cumberbatch, one of the most sought-after actors in film and television, gave an immediate "yes" to playing Turing.

"There is a huge burden, an onus of responsibility," Cumberbatch told Reuters on Sunday. "This was an extraordinary man and sadly, bizarrely not that well known a man of his achievements."

His Turing is terribly awkward and annoying, and when forced by the British government to work with a team of code-breakers, the lone genius is dismissive. When he doesn't get the backing for his machine, he sends a letter to Prime Minister Winston Churchill, who grants him his wishes.

DOSE OF HUMOR

For director Morten Tyldum, Cumberbatch "has that incredible screen charisma," adding "you can hold on to his face and you feel he has a million things going on through his eyes."

Keira Knightley plays mathematician Joan Clarke, who as the lone woman on the team bonds with Turing and becomes his fiance, although he later tells her he is gay.

Story continues

Tyldum, a Norwegian known for his 2011 hit "Headhunters," was drafted for the independent, modestly budgeted production after big Hollywood studios passed on the script.

People think "it's going to be a sad story and it's not," said Tyldum. "We wanted to make an entertaining movie. There's a lot of humor in it and, to me, it is a movie about hope."

Cumberbatch said the humor is true to Turing, whose niece relayed that "he was very funny in a very dry English way" and could joke about the forced estrogen injections of his sentence.

The humor also lightens the mood for a team tasked with the impossible, breaking through the millions of combinations to crack the German code while the war rages.

The math and the machine's workings will go right over most moviegoers' heads. But even the actors say they didn't get it either despite their best efforts.

"Benedict was working on the cryptic crosswords and he got further than I did, but we were all just faking it," said Knightley.

(Editing by Sandra Maler)