I managed, after some worry, to solve the message, and very few things in after life gave me as much pleasure as did the unraveling of that code -Houdini

Some of the first examples of the use of coded writing are found nearly 4000 years ago in tombs of ancient Egypt, in a chapter of the Book of the Dead, and on the sarcophagus of a pharaoh. In some instances the codes were used in an attempt to increase the mystery and perceived magical powers of the written words and their hidden meanings.
Those early coded messages were designed to spark interest and wonder in the reader and tempt the reader to solve the riddle.

The Kama Sutra lists secret writing as one of the 64 arts that women should know and practice. The list also includes prestidigitation, solution of verbal puzzles, exercises in enigmatic poetry, knowledge of changing one’s appearance, and tattoing.

Edgar Allan Poe used codes and secret messages in many of his poems and stories, including The Narrative of Arthur Gordon Pym and “The Gold-Bug,” but Poe also wrote about cryptology for the Philadelphia newspaper, Alexander’s Weekly Messenger, beginning in December 1839. After printing a riddle that had stumped one of the subscriber’s, Poe responded: “We sympathize with our correspondent’s perplexity, and hasten to remove it – especially as we have a penchant for riddles ourselves.” Poe then went on to challenge his readers to test him with other cryptographs.

Poe's association with Alexander’s Weekly Messenger ended in May, 1840, but he returned to the subject a year later as editor at Graham's Magazine, where he re-issued his challenge. It was during this time that one of Poe's readers, a Mr. W. B. Tyler, submitted two cryptographs for which Poe did not provide solutions. Of the 100-plus cryptographs submitted by his readers, these are the only two not solved. Poe claimed that he did not have the time to work out their solution, but published them in Graham's for his readers to decipher. There are some who claim that Poe was the author of the unsolved cryptographs.
In 1856 Charles Baudelaire published the French translation of “The Gold-Bug,” “Le Scarabee d’or.”

Arthur Conan Doyle utilizes codes and ciphers in three Sherlock Holmes stories, “The ‘Gloria Scott,’” “The Valley of Fear,” and “Adventure of the Dancing Men.” Holmes declares himself, “fairly familiar with all forms of secret writings, and am myself the author of a trifling monograph upon the subject.” Arthur Conan Doyle was friends with Harry Houdini, and one of few people with whom the magician had developed a code in order to communicate after he was dead.