History is punctuated with codes. Codes have decided the outcomes of battles and led to the deaths of kings and queens, or so says the author Simon Singh. In 1943, one of Nazi Germany’s most notorious communication codes was broken by a mild-mannered librarian and family man from Abbeyfeale in west Limerick, Richard Hayes.

His day job was director of the National Library of Ireland, but during the Emergency, he secretly led a covert team of cryptanalysts, working feverishly on the infamous “Görtz Cipher” – a fiendish Nazi code that had stumped many of the greatest code-breaking minds at Bletchley Park, the centre of British wartime cryptography.

Astonishingly, the feat was accomplished not in one of the huts at Bletchley Park, but in a now derelict building colloquially known as “The Red House” on Montpellier Hill in Dublin. If this wasn’t an amazing enough feat, Hayes also broke a complex microdot enciphering system which had baffled the American OSS, as well an enciphering system used by the dreaded Sicherheitsdienst (or SD), the intelligence section of the SS. The breaking of the latter code was instrumental in the Allied victory at the Battle of the Bulge.

Few individuals can be said to have altered the course of the second World War on their own, but Hayes was one such individual – and he did it not with a gun, but with a detailed knowledge of the complex algorithms and mathematical permutations involved in the art of cryptography.

In my new book Codebreaker, I didn’t set out to explain the mathematics behind the complex codes and ciphers that Hayes broke during the war. In truth, there are few even in the academic world who can. What the book, however, does attempt to do is recount the story of a long-forgotten, untold history of Ireland during the war – a history that has remained hidden in plain sight for the best part of 70 years.

It is a story where one man’s ingenuity, genius, patriotism and integrity saved this country from suffering the cruelties that were inflicted on so many other nations during the second World War. Hayes is, in my view, Ireland’s greatest unsung hero and it is my hope that others, having read the book, will also come to share this view.

To my shame, I, like many others, had never heard of Richard Hayes and only discovered his story in early 2017. Indeed, to most people, he is known only for his work as the country’s national librarian (a role in which he also excelled). My introduction to his story came in the form of an article in The Irish Times about the sale of a house at 245 Templeogue Road. The article had been shown to me by a teaching colleague who quipped to me, ‘There’s a story there,’ as I read through it.

245 Templeogue Road, Dublin: used by the IRA and where Nazi spy Hermann Görtz stayed in 1941

The house had been known colloquially as the “Nazi house” and its story was that of local lore in Dublin 6. It was erroneously said that the Art Deco house looked like a swastika in aerial photographs. While the house has an unusual shape, it doesn’t look like a swastika from the air. A swastika mosaic, however, was once situated on the floor in the hallway during the war years when the house was owned by IRA man and Nazi conspirator Stephen Carroll Held.

In 1940, the building was used as an IRA safe house and the most formidable Nazi spy sent to Ireland during the war, Hermann Görtz, stayed there on an ill-fated mission to Ireland to spy for the Third Reich.

In a footnote in a book on the subject, it mentioned that Görtz had been interrogated after his eventual arrest in 1941 by Hayes. Given my interest in history and a keen eye for a potential documentary idea, I decided to investigate the matter further. The result of this process was RTÉ Radio One’s Documentary on One, Richard Hayes Nazi Codebreaker, which was broadcast last year.

While the programme brought the story into the public domain for the first time and introduced Hayes to a wider audience, the story was much richer than a broadcast hour could allow. Therefore, a book was the natural choice to further tell this most remarkable of tales.

Finding written material on Hayes was a difficult task and indeed I’m often asked why he isn’t in the history books. There are a number of reasons for this. His work was subject to the Official Secrets Act; he was by nature a very discreet man and, most pertinently, he was lost in the construction of an historical narrative, crafted in a time of overt nationalism. It wasn’t “in the national interest” in the post-war world for the public to know how much Ireland had helped the British during the war when the nation was meant to have adhered to a “strict” policy of neutrality.

I was lucky enough to have had the benefit of a number of excellent primary sources. The most useful of these were Hayes’s papers in the National Library of Ireland. They were deposited in the library in 1980 by his second wife, Maura, and are a treasure trove of information consisting of numerous pages of mathematical calculations, as well as a detailed summary of his work. Hayes presented the summary to Taoiseach Éamon de Valera in 1946 and, in the document, he advocated the need for the creation of a permanent Irish cryptography unit (a suggestion that was never heeded).

I was also fortunate, during my research, to become acquainted with Richard’s daughter Faery and grandson Jim. Both were fountains of information and after many conversations and numerous cups of tea I was able to fill a lot of the gaps in the story and gain an insight into Hayes’s personality.

I was struck by the fact that while at the height of his battles with Hermann Görtz, and the myriad of other German spies landing in Ireland during the war, he still made time for his family. He remained a devoted family man throughout the whole period. Indeed, Hayes had a eureka moment while helping his eldest daughter Joan with her maths homework, which led to the cracking of one particularly notorious German code. Hayes scribbled the equation into a Browne & Nolan copybook; that very exercise book resides today in the Hayes collection in the National Library of Ireland.

It hope this book will go towards writing Richard Hayes and many of the other Irish heroes of the second World War back into the history books. While his name is not widely known, Hayes’s contribution to this country is immeasurable. When Ireland was at its most vulnerable, and when Britain stood alone in the world against Nazi Germany, our country was spared the horrors of the secon World War through the patriotism of a few brave men and the quiet heroism of a humble librarian.

We need to recognise the great bravery of Irishmen who stood against Fascism during the Emergency. I hope that someday Hayes and others will be officially commemorated by the state. Richard Hayes was a Renaissance man, our own Alan Turing, and one of this nation’s greatest patriots. It is the very least that he deserves.

Codebreaker: The Untold Story of Richard Hayes, the Dublin Librarian Who Helped Turn the Tide of World War II, published by Gill Books and priced at €16.99, is available now in all bookshops and online.