Richard James Hayes (Irish: Risteárd de Hae; born 1902, died 1976) was an Irish code-breaker during World War II and was Director of the National Library of Ireland.

Early life
Hayes was born in Abbeyfeale, County Limerick in 1902 and grew up in Claremorris, County Mayo. He was educated at Clongowes Wood College and Trinity College Dublin.

Cryptologist
It's not clear how Hayes, who joined the National Library with a degree in languages from Trinity College Dublin (TCD) was identified by army intelligence as a codebreaker. Colonel Dan Bryan, head of Ireland's G2 intelligence service, made the initial approaches to the newly appointed director in 1940 when a cipher was found on the first German agent to be captured in Ireland, Wilhelm Preetz. Hayes made significant progress in breaking the code and in February 1941, at the behest of Éamon de Valera, he was given an office and three lieutenants to decode wireless messages being covertly transmitted from a house in north Dublin owned by the German legation. One of his staff was Kevin Boland, son of the then justice minister Gerald Boland. The operation was so secret that the younger Boland was instructed not to tell his father what he was doing.

One of the most notorious German spies interned in Ireland during the war, Günther Schütz, described him as "absolutely brilliant". As far as Schütz and the other German spies whose cells he entered during the Emergency knew, their quiet-spoken and polite interrogator was "Captain Grey", a mysterious military figure always accompanied by another intelligence officer. Only a handful of people in G2 military intelligence knew that "Captain Grey", one of the most important and prolific code-breakers of the second World War, was not a military man at all.

Members of MI5 believed "his gifts amounted almost to genius" and described him as Ireland's "greatest unsung hero". The US Office of Strategic Services (OSS) characterised him as "a colossus of a man".

It is only in recent years that the importance and extent of Hayes's work has become known. During the war his own family didn't know the nature of his role with military intelligence. His daughter Faerie, aged seven when the war broke out, only learnt recently that her father used her school exercise book to decode complex German ciphers. Even Günther Schütz went to his grave in 1991 still believing that it was another man, Commandant de Butléir, who was responsible for identifying his microdot codes – the first cryptologist in the world to do so.

Schütz and Goertz
Günther Schütz was dropped into Ireland on 12 March 1941 to make contact with IRA members sympathetic to the German cause and to transmit weather reports back to his handlers in Hamburg.  Schütz readily gave up one of his codes to his Irish captors in the hope of diverting attention from his microdots, but a microscope in his luggage raised the suspicions of the authorities and his belongings were handed over to Hayes, who spotted Schütz's codes. In all, 30 pages of operating instructions as well as extensive lists of names and addresses of Nazi sympathisers in the Republic were secreted in random characters in newspaper cuttings that the German intelligence agent was carrying when he was picked up by gardaí in Wexford in 1941. Hayes studied two newspaper cuttings tucked into the spy's pocket book and in a testimonial letter affirming the curative qualities of Aspro, he identified messages, reduced in size 400 times, and secreted within three letter 'o's in the text. On an article about Oxford Pamphlets, he spotted a further four microdots, with three more in an ad for the Green Park Hotel. Within 10 days of Schütz's arrest, Hayes had found and translated the entire contents of his highly sensitive microdots. It would take the FBI a further four months to even identify that such a system of transmitting messages existed. "The Germans were so cocksure that the microdots couldn't be discovered that they didn't even encode them", Schütz said after the war. "They were to be a vital weapon in espionage. Finding them as the Irish intelligence officers did was an act of brilliance."

Hayes had some success decoding cable messages, but it was working on complex letter based ciphers that he demonstrated his brilliance as a code breaker. When Major Hermann Goertz, the most senior Nazi agent to be captured in Ireland, was arrested at the end of 1941, he was carrying a code later described by MI5 as "one of the best three or four in the war". A similar cipher had already baffled cryptologists at Bletchley Park, the headquarters of British code-breaking activity, but Hayes finally identified a system of decoding it based on a sequence of rotating keywords. The first of the Goertz messages to be successfully decoded was unlocked with the key 'Cathleen Ni Houlihan'. Informed of the breakthrough Hayes had made, Cecil Liddell of MI5 visited Dublin in 1943 and the two secret services continued to share intelligence information until the end of the war. Afterwards, Liddell said that there was a "whole series of ciphers that couldn't have been solved without Hayes's input".

Hayes advocated the establishment of a permanent cryptology cell within the armed forces. In 1946, Hayes wrote to the government, advising that "it is to be hoped that the Irish army will never again face an emergency so ill-provided in this essential security device".

Librarian
Throughout his time with G2, Richard Hayes continued to visit his office at the National Library every day. He had joined the Library in 1923 and served as Director 1940–67. During his time in the Library he made an enormous contribution to Irish bibliography, editing the following publications:
 Manuscript Sources for the History of Irish Civilisation. (1965)
 Sources for the History of Irish Civilisation: Articles in Irish Periodicals. (1970)
 with Brighid Ní Dhonnchadha, Clár Litridheacht na Nua-Ghaedhilge. (1938)

He also compiled the first major bilingual dictionary between Irish and a language other than English since the 1700s i.e. French

When there was a danger that the Ormonde papers might be sold and leave the country, he prevailed on the government to introduce the Documents and Pictures(Regulation of Export)Act 1945.
When he retired as director in 1967 he took over the helm at the Chester Beatty Library. RTÉ has archived a television interview with Hayes about the Chester Beatty collection, on the occasion of the reopening of the Chester Beatty Library in 1975 at its then location on Shrewsbury Road.
Hayes died in 1976, leaving behind a collection of papers and manuscripts that is now catalogued in the National Library.

Personal life
Hayes was a lifelong atheist.

References

Further reading
</ref>

1902 births
Irish cryptographers
People educated at Clongowes Wood College
People from Abbeyfeale
Alumni of Trinity College Dublin
1976 deaths
Irish librarians
20th-century Irish mathematicians
Irish atheists