GCHQ once made “major mistakes” in its coding systems and had a near 30-year ban on hiring staff who were not white, according to its first authorised history.

Author John Ferris said it was important he provided a “warts and all account” of the security agency’s 100-year past, outlining its secret successes and failings, when he was selected to write the book.

Published on Tuesday, Behind the Enigma promises to reveal never previously known details about Government Communications Headquarters – which works alongside MI5 and MI5 to tackle cyber, terrorist, criminal and state threats and attacks.

The intelligence service commissioned the first ever authorised history as part of its efforts to open up more to the public as it marked its centenary year.

Mr Ferris, a professor of history at the University of Calgary – who also has a PhD in War Studies from King’s College London and has published work on academic studies on diplomatic, intelligence and military history, spent four-and-a-half years working on the title.

During this time, he was given “unprecedented access” to GCHQ’s archive and policy files, examining around 16million artefacts – many of which were previously classified and have never before been made public.

John Ferris
Author of the authorised history of GCHQ Behind the Enigma, John Ferris (Laura Grace Photography) /PA)

Speaking to the PA news agency, Mr Ferris said: “They (GCHQ) remain today the one British strategic and intelligence agency that’s at the top of the world.

“And so it gives Britain a great deal of power and influence.

“I think it is essential that I did a warts and all account and GCHQ, to its credit, was willing to let me do that.

“So if you look at the things I’ve found which they wish hadn’t happened.

“For example, there is a ‘colour bar’ in employment in GCHQ in the 1950s and 1960s.

“In other words if you’re not Caucasian, they don’t want you in. And they take active measures to avoid hiring you.

“And, by the way, that’s what all British security and intelligence organisations do at the time.”

Behind the Enigma
Front cover of the first authorised history of GCHQ (Bloomsbury/PA)

He described a “mixed” picture on job opportunities for women and people from BAME backgrounds.

But explained by contemporary British standards – among white men of all classes – GCHQ’s personnel was diverse, especially for managerial positions.

He said his research showed GCHQ was “surprisingly diverse” for working class men and, “in many ways astonishingly open to working class men”, compared to other Government departments and agencies who would typically hire university graduates.

According to the book, while it was possible, few non-white staff would have applied at the time as “racism would likely have constrained the chances of any who did apply”.

The rule was in place until around 1980, and eventually abolished.

Mr Ferris said there were “many things that GCHQ does that they’ve not done well, or in hindsight they would be unhappy about”, highlighting another example: “In the 1930s, the British make major mistakes in their coding systems, which means that when the war breaks out actually they are very vulnerable to German and Italian code breakers.

“And they suffer some losses as a result.

“It takes the British a couple of painful years to overcome those weaknesses.”

The book also sets out how GCHQ’s work influenced some of the major international incidents of the last century, including the Cold and Falklands wars.

Mr Ferris told how GCHQ did “extremely well” in its Cold War efforts on “very limited budgets” and described the Falklands as an example of where GCHQ “most affected British policy”.

He added: “In the Falklands conflict of 1982 I’d say that GCHQ was fundamental to British victory.

“Without GCHQ I don’t think the conflict could have been won.

“Really it was one of the necessary things for victory.”

Duchess of Cornwall visits Bletchley Park
The Mansion House at Bletchley Park (PA)

Established on November 1 1919 as a peacetime “cryptanalytic” unit made up from staff from the Admiralty’s Room 40 and the War Office’s MI1(b), GCHQ personnel moved to Bletchley Park during the Second World War where they decrypted German messages, most famously by breaking the Enigma code.

The agency’s best-known former member of staff was Alan Turing, the wartime code-breaker and pioneer of computer science who had a “fearless approach to daunting problems”.

The organisation rarely speaks publicly about its work and its existence was not publicly acknowledged until 1983, although it has tried to be less secretive in recent years.

In 2016, it became the first of the country’s spy agencies on Twitter and has since joined Instagram.

Last year, to mark its centenary, it revealed the locations of five formerly secret sites it had been working from during the Second World War and the Cold War.

In a foreword to the book, GCHQ director Jeremy Fleming said the Mr Ferris’ narrative “shows us as an organisation set up to collect and analyse intelligence and with an amazing track record of shortening wars, countering hostile states, thwarting terrorist attacks and disrupting serious criminals”, adding that the agency’s future success will be “assured if we retain and recruit a diverse mix of minds. This history shows that when we do, anything is possible.”

Behind the Enigma is published on Tuesday by Bloomsbury, priced £30.