Before the advent of email, modern spy agencies had to break codes hidden within telegraphs in order to read them. And in at least once case in the early 20th century, the U.S. government used surveillance and codecracking to score a major diplomatic victory against Japan during a major international meeting.

Herbert Yardley was a former railroad telegrapher who later became a government "code clerk." He proved the value of his code-breaking chops throughout World War I, and after the war the State Department officially set up a "Cipher Bureau." (As if that name wasn't nefarious-sounding enough, it was also known as "The Black Chamber.") It was America's first permanent code-cracking agency, and it was the precursor for today's National Security Agency. Yardley became the head, setting up the offices on East 38th Street in New York, across the street from a department store. He and his wife lived on one floor, and the bureau took up the rest of the building.

(Why New York? "Washington is overrun with spies," Yardley said, without any apparent irony.)

At the time, diplomatic messages were written not only in foreign languages, but also with some words substituted with numbers or code words. It was the Cipher Bureau's job to make sense of the code and then translate the entire message.

David Kahn, who has written extensively about Yardley and code-breaking, said it was not unlike solving a puzzle:

"It was about looking at frequencies and guessing at what they were," Kahn said.

The bureau largely concerned itself with cracking messages sent by the Cheka, the Russian secret police, and by various South American governments. But by far the big codebreaking target was Japan.

"Its naval growth menaced American power in the western Pacific. Its commercial expansion threatened American dominance of Far Eastern markets," Kahn wrote in a book about Yardley. Yardley didn't speak Japanese, but he at one point told his boss he would resign within a year if he couldn't crack the Japanese codes.

There were a number of ways to eavesdrop on a telegraph, but Yardley found the easiest. He and his employees would simply go down to the local Western Union office and ask the telegraph operators for copies of the Japanese messages, Kahn said. And like Facebook or Google in today's NSA scandal, the workers found it hard to say "no."

A golden opportunity to spy on the Japanese came in 1921, during a conference that aimed to limit naval capability among the world's powers as a way of curbing the war-ship arms race at the time.

The U.S. wanted Japan to concede to having fewer ships, but Japan wanted slightly more. With Yardley's code-cracking, the U.S. discovered that it was more important to the Japanese to preserve their relationship with the U.S. than to be able to spend more on their navy.