# Secret Code III

I’ve been enjoying science fiction author Robert J. Sawyer. I wrote about the first three books I read in the previous post. Just after writing that post, I finished a fourth book, Triggers (2012), a present-day political thriller involving accidentally linked minds — one of which belongs to the POTUS.

I liked the story quite a bit, some of it so much I’m inclined to give it a Wow! rating. It was fun, and it presents some tasty food for thought. And I don’t intend to get much into any of that.

Instead, this is about a simple secret code used in the book. It was new to me, and I found it clever, so I thought I’d dash off a quick post about it.

I’ve been fascinated by secret codes and encryption (and codebreaking!) for a very long time. When I was a kid, my dad and I would sometimes make up codes, write a message in code, and see if the other could break it. We used simple substitution codes, so we weren’t at all sophisticated. It was basic decoder ring stuff.

Ever since, the myriad of schemes, simple and complex, for encoding messages has been a minor fascination. (I posted about those early days back in 2015 and more recently about other codes from books. See The Playfair Cipher and Secret Code II. And now you see why this is Secret Code III.)

§

At the fundamental level, an encoding is a numerical map from one ordered set of numbers to another ordered set of numbers. In some cases, the map is bidirectional — the same map takes cleartext to encrypted text and encrypted text to cleartext. In other cases, separate maps encrypt and decrypt.

The process of applying a map may be symmetrical or asymmetrical depending, respectively, on whether the same process encrypts and decrypts or if the two are distinct. (In some cases, distinct maps and distinct processes amount to the same thing — a special asymmetry between cleartext and encoded text. A familiar example of this is the zip-unzip process.)

A critical property for encryption security is that an encoding map depend on context. A context-free map always maps an input number to the same output number. A contextual map uses previous numbers or position or some other variable to change what output results from a given input. (The infamous Enigma machine was contextual. Each character advanced the machine to a new map.)

Context-free maps are generally substitution ciphers (“decoder rings”) and trivially easy to break. They can hide a message only from the most casual eyes (which still makes them somewhat useful). Some well-known ones, like ROT13, serve mainly to mask content from accidental viewing.

As an aside: some maps aren’t intended to be secure in any sense but are only protocols that map some form of data to numbers. Unicode, for instance, maps all the glyphs from all the common languages of the world, plus many special symbols (including the standard set of emojis), to a set of numbers that computers can process and exchange. Maps like this depend on being fully known to all (to the point of being standards). They’re almost always context-free and symmetrical.

§

Cracking an unknown substitution cipher just needs a long enough message for character analysis. Short messages can be reasonably secure, especially when the mapping is changed for each message. (In the book, the message was quite long, so it would have been easy to crack had anyone cared to try.)

The problem with changing the mapping is that both sides need to know which map to use. One solution involves a code book listing mappings that are used according to some schedule or cue. Alternately, there can be a protocol for creating a new mapping. Then both sides need to know the key or “seed” to create the map. As a simple example, a decoder ring set to a random new location each time and that setting included in the message (or communicated elsewise).

In any event, both sides need to know the mapping and how to use it. That last part is important, too. A decoder ring, for instance, just slides the alphabet back and forth. Effectively, the process adds a fixed number to each input character (wrapping around to the beginning if necessary) to get an output character.

Decoding in this case is a different process because it involves subtracting that fixed amount. The exception is ROT13, where the fixed amount is 13. Since 13 is half of 26, adding twice is the same as adding then subtracting. So, the same process encodes and decodes in the specific case the decoder ring is set to 13.

The point is: The process might be “decoder ring” substitution cipher. It would then have a setting — some number from one to 25. Together they are the key to the code.

§

The code presented in Triggers is a substitution cipher — something the POTUS remembers from his youth. He made it up so he could exchange secret messages with his high school buddy. In the book, because another character is linked to his memories, that character uses the memory of the code to send an “eyes only” message to the President.

Essentially, the protocol breaks the alphabet into three separate decoder sub-rings. What allows the code to vary is that the three decoder sub-rings can be different sizes. The setting is a three-number sequence specifying those sizes. For instance: 5, 3, 5.

The restriction is that the three must sum to 13. And each should be larger than 1.

Given some setting of three numbers, do the following for each number:

1. List that many of the next available letters of the alphabet
2. With listed letter, pair the next available letter in order.

The process should use up all 26 letters of the alphabet. If you run out of letters, or have any left over, check that the three numbers add up to 13 and that you followed the steps carefully.

To illustrate, using the above example of 5, 3, 5:

1. For the (first) number 5, step one gives us: A, B, C, D, E.
2. Step two gives us: A=F, B=G, C=H, D=I, E=J.
3. For the number 3, step one gives us: K, L, M.
4. Step two gives us: K=N, L=O, M=P.
5. For the (other) number 5, step one gives us: Q, R, S, T, U.
6. Step two gives us: Q=V, R=W, S=X, T=Y, U=Z.

The combination of the three gives us the total map. Note that it is “folded” such that half the characters appear on the left of the equals and half appear on the right. Encoding or decoding a message requires finding the character to encode and using whatever character is on the other side of the equals.

[When I wrote a Python script to implement this code, I created table entries for both left and right characters. The table had, for instance, both A=F and F=A. This to allow indexing from the left side only.]

§

A given mapping is bidirectional — it both encodes and decodes a message. It’s also context-free (as all substitution ciphers are). And it’s symmetrical. The same process using the same map encodes and decodes.

As used by the young President-to-be, the three numbers are put at the beginning of the message. That allows the recipient to build their own table.

Here’s a sample encoding:

6 4 3 VSX IGRP HK G NKGF ISXRPNV XRFKOO VSX BGYK G HKKN GRJ GR GCNFCRK CP BKFTO CL VSX BGYK OSQK ECRJ SL G LSSPHGFF PKGQ SN OSQK RXIFKGN ZKGTSRO HXP GP PBK YKNV FKGOP VSX RKKJ G HKKN

The three numbers at the beginning tell you how to build the mapping.

As always with simple codes, it uses only the alphabetic characters A-Z and those only in uppercase. Numbers or punctuation must be spelled out as in the telegrams of yore (“IT WAS FORTYTWO NOT SIXTYTWO STOP PLEASE FIX ASAP EXCLAMATION”)

We also don’t use spaces, so generally all the letters are run together and then spaces are inserted randomly. In some cases, letters are grouped in same-sized chunks (typically groups of five). This requires a little effort to decode:

6 2 5 XMOKX ZHDKI YXGWK XMXKW CMZXY BGYMP KIGPM PFTDM EKGHM ZYYBK OSSSS

Decodes to:

Which requires a little disambiguation to get:

Some subjects are so serious that one can only joke about them.

But it’s usually not too difficult.

If desired, there are ways of expanding the character set to include spaces and some punctuation. It mostly involves adding whatever you want to the list of characters in the mapping.

One option, although it makes the encoding much less secure, is to just preserve the spaces as spaces (and punctuation as punctuation):

6 2 5 XMOK XZHDKIYX GWK XM XKWCMZX YBGY MPK IGP MPFT DMEK GHMZY YBKO.

But that gives away the shape of the words and sentences and makes the code very easy to crack (especially with the single-character words “A” and “I”).

§

Anyway, that’s all there is to it. Build the table using three numbers that sum to 13 and use that table as a code mapping. Just be sure to make sure the recipient knows the triple number by including it in the message or by some other means.

The code is only one step up from a decoder ring, but it might be a fun thing to share with your kids.

§ §

Triggers involves an assassination attempt against the POTUS during a speech at the Lincoln Memorial. The severely wounded President is rushed to the hospital. During the operation, a powerful terrorist bomb destroys the White House. While not nuclear, the device uses a new technology that creates intense heat and an EMP. The latter causes a power disruption at the hospital during the operation to save the President’s life.

Meanwhile, in a nearby lab, the surge current from the power disruption causes a quantum scanning device to create a spherical quantum field large enough to include 21 people who happen to be in the vicinity — including the operating room with the President and his surgical team (and the fetus of nearby pregnant woman).

The quantum field links the 21 minds in a daisy chain loop: #1 → #2 → #3 → … #20 → #21 → #1. The problem for the Secret Service Agent Susan Dawson is that, since the President is in the loop (and so is she), someone has access to everything the POTUS knows. (And someone else has access to all her memories.)

The book’s title comes from the need to trigger a memory to access it.

Stay mapped, my friends! Go forth and spread beauty and light.

The canonical fool on the hill watching the sunset and the rotation of the planet and thinking what he imagines are large thoughts. View all posts by Wyrd Smythe

#### 6 responses to “Secret Code III”

• Wyrd Smythe

4 5 4 N GEIIJX MARARFAM XDA FJJPW NZA MAEH EIU RJMA XDEI XDA RAEQW N DEZA AEXAI AZAI WJ XDAU DEZA REHA RA

• String Evolution | Logos con carne

[…] Last post I wrote about a simple substitution cipher Robert J. Sawyer used in his 2012 science fiction political thriller, Triggers. This post I’m writing about a completely different cool thing from a different book by Sawyer, The Terminal Experiment. Published in 1995, it’s one of his earlier novels. It won both a Nebula and a Hugo. […]

• Wyrd Smythe

7 3 3 HPHZV LOJ RKLKF LPPHNLBP HNO LHQ ZHVQREL HYLGHPQ VNO HFPR SLGSHOLG LPS LJBH EEVRGR QALOS RPQP IHGNJER PLSHO LGPQRSGR RGLL YLOIRQ ALO PQR KLJRKLQ ALP LPQRS

• Sci-Fi Saturday 8/13/22 | Logos con carne

[…] The post immediately after it touched (briefly) on a fourth, Triggers (2012). That one starts off as a political thriller involving an assassination attempt against the POTUS and turns into an uplifting very science fiction story about the unified consciousness of all humanity. It not entirely incidentally uses a simple secret code (a substitution cypher) that I thought was cute and wrote the post about. […]

• Sawyer: WWW | Logos con carne

[…] bias on my part. I’ve posted about him (twice) recently. Ideas in his books account for two other posts. I can’t say every book is a home run, but they are all at least extra base hits […]