From Code Girls, by Liza Mundy (Hachette, 2017), Kindle pp. 82-83:
Technically, there are two kinds of secret message systems. One kind is a code, in which an entire word or phrase is replaced by another word, a series of letters, or a string of numbers, known as a “code group.” A code may be used for secrecy, but also for brevity and truncation. Shorthand is a code in precisely this way and so, often, is modern-day texting. Common phrases, even long ones, can be compressed into short code groups, making messages faster and—when using cable, as many people did in the early decades of the twentieth century—cheaper to send. Saving money has always been important to governments, so the compression advantage is a big deal. Cable companies typically charged by the word, so the fact that stock phrases like “your request of last month has been approved” could be boiled down to a code group, as could the names of places or people or units, meant governments could save a good bit of money when sending telegrams. In the War Department’s “general address and signature” code that was employed in 1925, for example, the word “cavalry” was HUNUG, “Pursuit Squadron” was LYLIV, “Bombardment Squadron” was BEBAX, “Wagon Company” was DIGUF, “U.S. Naval Academy” was HOFOW, and “Fourth Division Air Service” was BABAZ. (Texting uses codes, like OMG and IMO, for much the same reason: brevity and, at times, concealment.) The best code is one in which code groups are randomly assigned, with no rhyme or reason that an enemy can discern. Codes are compiled and kept in codebooks, not unlike dictionaries, where the encoder can look up the word or phrase and the corresponding group that stands for it. But even random codes have an obvious vulnerability: Constant repetitious use of the same code groups in messages enables code breakers to tease out their meaning from context or position.
The other type of system is called a cipher, in which a single letter—or number—is replaced by another single letter or number. Ciphers can be created by scrambling letters, which is called transposition—turning the word “brain,” for example, into “nirab.” Or a cipher can be achieved by replacing individual units with other units, a method called substitution: By substituting X for b, T for r, V for a, O for i, and P for n, for example, brain becomes “XTVOP.” For centuries, ciphers were created by hand, often by those clever Renaissance men who would line alphabets up against one another and create boxes and tables that gave a way to substitute one letter for another. But when radio and telegraph came along, messages could be sent much, much faster than a wigwag flag could do. Machines were needed that could encipher rapidly; and, because it became easier to spot simple patterns when so many messages were being sent and intercepted, more complicated ciphers were needed. People can make complex ciphers, but people make mistakes. Machines are less likely to do so. These machines created an early form of what would later be called encryption, which meant that people who broke them might be described as an early version of what would later be called hackers.