David E. Hoffman is a contributing editor to The Post and author of “The Billion Dollar Spy: A True Story of Cold War Espionage and Betrayal.”

The “one-time pad” is a simple but secure way to encipher a message. The text of the message is converted into numbers using a page of code. When the recipient gets the message, it is deciphered using the identical code. The page of code is used only once and then torn from the pad and discarded, never to be used again.

It is nearly impossible to break and was used effectively by the Soviet Union in the final years of World War II and just after. Code-breakers in the U.S. Army and Navy despaired at the difficulty of cracking it. “If the standard work of a codebreaker was looking for the proverbial needle in a haystack, the Russian problem required finding a wisp of straw in a haystack,” Stephen Budiansky writes in “Code Warriors,” his richly detailed look at the rise of the National Security Agency and its long struggle to penetrate Soviet communications in the Cold War. Budiansky does an admirable job of depicting the early years of the NSA, but he runs up against walls of secrecy that still surround the history of code-breakers and snoops in the final stages of the great confrontation between East and West.

After using one-time pads successfully during World War II, the Soviet communications people got careless. They used some a second time, “an astonishing and monumental security blunder,” Budiansky recalls. A defector also offered an inside view of how the Soviet networks functioned. The Americans began to break the messages, in particular the traffic from 1943 to 1945 over a Soviet diplomatic channel. They made the stunning discovery that the channel was carrying secret messages to Soviet spies abroad from the NKGB, the Soviet foreign intelligence service later to become the KGB. This gave rise to the U.S. counterintelligence project known as Venona, which eventually broke nearly half of the 1944 messages between New York and Moscow. According to Budiansky, the U.S. cryptanalysts concluded that the sloppy procedures — the reuse of one-time pads — was “the result of wartime disruptions that forced Soviet printing plants to cut corners for a few months in early 1942.”

The mistake helped the United States discover Soviet atomic bomb espionage, among other things. The deciphered messages also showed that the Soviets were “extremely old hands at this game,” and in spying displayed “the hallmarks of a professionalism of a kind that their Western adversaries were neophytes at by comparison.”

"Code Warriors: NSA's Codebreakers and the Secret Intelligence War Against the Soviet Union" by Stephen Budiansky (Knopf)

The Venona project has been public for more than two decades, yet Budiansky’s retelling of it, early in this book, whets a reader’s appetite. One feels the anxiety of the code-breakers as they struggle to do the near-impossible. Budiansky makes it real with detailed — and sometimes dense — explanations of how cryptography works. The book has five technical appendixes, too. While some of the intricacies are difficult to grasp — the depths, busts and additives — the overall narrative is fascinating and clear.

On Nov. 1, 1948, the Soviet Union “slammed the cryptanalytic door shut” with a series of changes to make messages “completely unbreakable.” This was a huge setback for the American code-breakers. The reader can’t help but wonder: How do the wizards of cryptography get back in the game?

For a long time, they don’t. In the 1950s, the Americans were unable to break the high-level Soviet codes. Budiansky shows how this sent them scrambling to use other methods to learn what the Soviets were up to, such as collecting reams of unciphered telegrams, transmitted by radio, often about things as mundane as railcar loadings and labor problems. Airplanes conducted “ferret missions,” flying along the Soviet borders, to collect electronic signals from Soviet radars. The United States dug a tunnel in Berlin to tap Soviet communications cables. Valuable intercepts were harvested from Soviet pilots during the Korean War.

President Harry Truman formally created the National Security Agency on Oct. 24, 1952, and ground was broken for the headquarters at Fort Meade, Md., in 1954. The agency’s workforce tripled in the 1950s to 12,000 people, and the military cryptologic agencies ballooned to 60,000 in the same period. But despite big investments in computers and personnel, despite mountains of intercepted messages and data, the quest to crack the high-level Soviet codes remained stalled, and “no breakthroughs had been achieved.” It should be noted that the CIA ran two productive spies against Moscow in the early Cold War but also suffered through a long period in the 1960s and early 1970s when the returns on human source espionage against the Soviet Union were paltry.

For the code-breakers, especially troublesome was a Soviet enciphering system known as Albatross. Five years of sifting through 1 million Albatross messages had produced hardly anything, not even a sense of how the coding machine worked. Some experts “glumly concluded that by far the best hope for a quick solution” lay in stealing one. The next-generation Soviet machine, code-named Fialka, was even harder to crack. Although there were successes in signals intelligence through the years, Soviet codes remained stubbornly impenetrable. Budiansky recalls that a crash computer program costing $20 million in 1957 could still only exploit about 3 percent of a Soviet cipher known as Silver. At the time of the Cuban missile crisis in 1962, Budiansky reports, “the inability to decipher any of the high-level cryptographic systems of the Soviet government or military was continuing to take its toll.”

At this point, a reader is eager to learn how the cryptanalysts of the NSA fought back, but Budiansky offers precious little detail about how code warriors functioned in the 1970s and 1980s. Instead, in the latter half of the book, he broadens his scope to examine the NSA’s burgeoning size and competition with the CIA; the growing importance of satellites; the NSA’s checkered record in the Vietnam War; the Watergate-era intelligence probes; and the agency’s reliance on methods other than code-breaking, such as electronics interception, traffic analysis and plain-language intercepts.

All of this is well and good, but Budiansky never returns to ground zero. His vivid account of the 1940s is not matched in the tense later years of the Cold War. Much of the history of the past few decades is still classified and may have been beyond the author’s reach. The book is based largely on the existing declassified record.

Near the very end of the book, Budiansky hints at a cryptanalytic breakthrough against Soviet ciphers in the 1979 Soviet invasion of Afghanistan, again without much detail. Budiansky describes it as a “triumph” and a “a last hurrah for the golden age of codebreaking” that had begun before World War II. From then on, he suggests, the bountiful targets for the NSA were not messages enciphered with one-time pads but rather troves of data moving on computer networks, posing new challenges.

Surely there is a great story waiting to be told about the men and women in the trenches of this immense battle, which continued well after the Cold War and goes on today. The NSA became a vast and powerful intelligence agency in the digital age. This book illuminates the early years, but some of the best tales are clearly still to be told.