A trio of codebreakers has accidentally stumbled upon a lost series of secret letters written by Mary, Queen of Scots in the years before her execution in 1587.

The incredible, seven-year-long correspondence was encrypted so successfully, the documents were archived in an unmarked file and mistakenly placed in a part of France's national library involved with Italian affairs.

When researchers randomly stumbled upon the 57 letters, however, it was clear none of them had anything to do with Italy. They were written in French and appeared to contain a sophisticated cipher system based on mysterious symbols.

A previously found coded message between Mary and Chateauneuf, the French ambassador in London after Castelnau. (British National Archives)

When cryptographer and computer scientist George Lasry, music professor Norbert Biermann, and physicist Satoshi Tomokiyo finally broke the code, they were shocked to find out whose words they were reading.

Mary Stuart was born Queen of Scotland in 1542, and yet she spent much of her life imprisoned; first in Scotland by Protestant revolutionaries and then in England by her cousin Queen Elizabeth I, who saw her as a threat to the throne. Mary was Catholic, and those of her religion in England felt she should be the nation's leader.

Over the course of her life, Mary was involved in several attempted Catholic rebellions, which she supported through heavily encoded letters.

This particular correspondence was revealed to be her long-lost letters to Michel de Castelnau de Mauvissière, the French diplomat to England in the mid 16th century and a known Catholic ally. Historians have long suspected these two were in cahoots, but until now, their letters never surfaced.

John Guy, an expert and biographer of Mary, Queen of Scots calls the discovery "fabulous" and "a literary and historical sensation".

"This is the most important new find on Mary Queen of Scots for 100 years," Guy exclaims.

"I'd always wondered if de Castelnau's originals could turn up one day, buried in the Bibliotheque Nationale de France (BNF) or perhaps somewhere else, unidentified because of the ciphering.

"And now they have."

Castelnau Codes
An example of a recently found coded message between Mary and Castelnau. (BNF)

Mary's communication with the outside world was practically an open secret of the time. Even English officials knew what she was up to, and yet for many years, her channels with the outside world were apparently so secure that many of her letters have simply disappeared.

Altogether, the letters with de Castelnau contain more than 50,000 words of primary material, revealing new insights into the forcefully abdicated Scottish queen's personal views, health, allegiances, and plots.

On April 16, 1583, for instance, Mary wrote an encrypted letter in which she thanked de Castelnau for his continued support.

A translation reads, "I cannot thank you enough for the care, vigilance and entirely good affection with which I see that you embrace everything that concerns me and I beg you to continue to do so more strongly than ever, especially for my said release to which I see the queen of England quite inclined. If it brings any success, be assured that I will acknowledge as much as I can your good services with her, and the obligation I have for you from the past."

But Mary's letters were not always so secretly kept. Many times they were intercepted or simply sent back to her.

In 1585, Mary's jailor was replaced with a much stricter fellow, who attempted to end all her private communications.

When Mary tried to support a 1586 plot to get her back on the throne, a spy in her communication channel proved to be her end.

The next year she was executed for treason.

The discovery of these long-lost messages to de Castelnau may be some of the last letters Mary ever wrote, although an analysis of the handwriting suggests various people were involved in actually scripting the ciphered words.

"Due to the sheer amount of deciphered material, about 50,000 words in total and enough to fill a book, we have only provided preliminary summaries of the letters, as well as the full reproduction of a few of them, hoping to provide enough incentive to historians with the relevant expertise to engage in in-depth analysis of their contents, to extract insights that would enrich our perspective on Mary's captivity," the codebreakers write.

The study was published in Cryptologia.