Ternary and Code-breaking

Facebooktwittermail

In Slave to Fortune the central character, Tom Cheke, uses ‘ternary’ to decipher a coded message belonging to French agents that has been intercepted by the Order of St John. This post explains what ternary is and how it is used to decipher the code. It will also show you how to count to 242 on the fingers of just one hand, if you’re so inclined.

Ternary (also known as trinary) is the base-3 numeral system – just as the much better-known binary is the base-2 numeral system. The table below shows how ternary numbers correspond to our usual (decimal or base-10) way of counting:

Ternary Decimal Ternary Decimal
1 1 112 14
2 2 120 15
10 3 121 16
11 4 122 17
12 5 200 18
20 6 201 19
21 7 202 20
22 8 210 21
100 9 211 22
101 10 212 23
102 11 220 24
110 12 221 25
111 13 222 26

Though he would never have heard of the word ‘ternary’, Tom uses it in practice to decipher the code, having been taught a ternary counting method during the early stages of his adventures.

Jack, the cook aboard Tom’s first ship and a convert to Islam, teaches Tom how to count up to 100 on the fingers of one hand. In so doing, he shows Tom how to count the 100 short prayers (or dhikr) of the Tasbih on his fingers as an alternative to using Misbaha beads to keep a tally. (Readers of the novel may have noted that Misbaha beads and their broad Christian equivalent, Rosary beads, appear on several occasions in Tom’s memoir.) Many poor Muslims in Tom’s time would have used their fingers to count the Tasbih rather than prayer beads, and indeed some forms of Islam believe finger-counting to be the orthodox method of counting the prayers.

We do not know which precise method of finger-counting was orginally used for counting the Tasbih. As one Islamic scholar, Shaykh Assim Al-Hakeem explains: “There is no explicit statement with regard to the exact manner in which the Prophet (P.B.U.H.) performed dhikr with his right hand; i.e., the manner of counting on the finger joints, other than the number of times for saying each. All that is known is that one should make dhikr on the right hand with their fingers, as this is the Sunnah.”

In practice, there is more than one way in which to count up to 100 on one hand, and the method that Tom learns from Jack and later applies to crack the code is not the most common method used today. Jack – back in the 17th century – uses a method that involves each finger having three positions – down, half up, and fully extended – each position signifying one of the three ternary numerals as demonstrated in the following table.

Finger positions Ternary Number Decimal number
 Ternary 1 1 1
 Ternary 2 2 2
 Ternary 12 12 5
 Ternary 22 22 8
 Ternary 222 222 26

Key to understanding this method is to remember that a fully extended digit always signifies a ‘2’ in ternary, a half extended digit always signifies a ‘1’, and a digit fully down always signifies a ‘0’. With the palm facing towards you, the fingers can then be read from left to right to give the number in ternary form. The ternary-decimal conversion table above will help you to translate from the ternary numbers into standard decimal numbers up to 26, or you could use an on-line conversion tool to convert any number you like (and also in quaternary, quinary etc).

A key aid in helping Tom to crack the code was his companion Edward Hamilton’s explanation of how the renowned contemporary English scholar, Francis Bacon, had – in effect – created a binary code using just two letters, say A and B, to encrypt messages.

When Tom examines the French cipher – you can see the cipher in Can you crack the code? he realises that only three symbols are routinely used in it. In this case, the symbols are suits of playing cards. Through a bit of lateral thinking relating to Jack’s finger-counting method, Tom realises that Francis Bacon’s method of encryption could readily work with three letters, or symbols or finger positions instead of two and that this would enable enables messages to be encrypted much more succinctly.

For example, only three fingers (with three finger positions) are required to count up to 26 – all that’s required to generate each letter of the alphabet. (If you’re interested: four fingers fully extended would be ternary 2222 = 80 decimal; five fully extended would be 22222 = 242). Once Tom has worked this out, it does not take him long to translate the card suits into numbers, first ternary then decimal, and then into letters to fully decipher the code.

Of course, ternary can be used for many other purposes beyond encrypting secret codes. As a numeral system, ternary has a number of particular properties that appeal to mathematicians. It has also been used as a basis for computing (but note that the equivalent of binary computing’s ‘bit’ is a ‘trit’!).

One mathematician, Brian Hayes, has described ternary as ‘the Goldilocks choice among numbering systems: When base 2 is too small and base 10 is too big, base 3 is just right.’ He goes on to argue that ternary is ‘the most efficient of all integer bases; it offers the most economical way of representing numbers.’ However, despite this advantage, the fact that most people have never heard of ternary indicates by how much it is overshadowed by its binary and decimal counterparts.

Will ternary ever catch on and become widely used? Not, I suspect, for as long as (most of us) are born with ten fingers and toes, and many of our other body parts come in pairs. It’s a reflection of how our anatomy has shaped our way of understanding the world around us.

Facebooktwittermail