Some messages were sent through relays, or the lines could be tapped, I wonder if any telegraph operators encrypted their messages using a shared key.
There were various standardized codebooks published for when the message was not secret and compression was the only consideration:
https://en.wikipedia.org/wiki/Commercial_code_(communication...
Frequent telegraph users with an additional need for secrecy, such as investment bankers, developed similar proprietary in-house codebooks.