Coded messages were needed during the Civil War because telegraph lines could be wiretapped. To prevent the enemy from learning the message, they coded their message.  The sender and receiver had the codebooks to decode the message.  Of course the system fell apart if the codebooks got into the wrong hands or spies copied the codebooks.