In the spring of 1939, Pamela Kirrage, headstrong and beautiful, met Donald Hill, a handsome RAF pilot. After a golden summer of courtship, they became engaged. In September, with Britain now in conflict with Germany, their plans disintegrated.
Hill was transferred to Hong Kong. Sensing that he was caught up in the sweep of great events, he began a diary in an old school exercise book. However, officers serving abroad were forbidden to keep such records, so Hill devised a secret code that transformed his words into numbers. When Hong Kong fell to the Japanese and Donald was captured and sent to a prisoner of war camp, he took his diary with him.
The Donald Hill who returned from the war, after four brutal years of incarceration, was a dramatically changed man. Though he and Pamela married quickly, once the relief and emotion of their reunion had subsided, it was obvious that Donald had been scarred deeply by his experiences. Eventually, tortured by savage flashbacks, he was confined to hospital.
Pamela had always known that the numbers in the school book were a code and that somewhere within the lines of figures she would discover the key to understanding the man she loved. Eventually, she found a mathematician who was able to decode the diary and reveal its secrets.
The Code of Love is Andro Linklater's portrait of a woman's search, for over fifty years, to discover the truth about the man to whom she had devoted her life. It is an unforgettable book.
The Code of Love, published by Weidenfeld & Nicolson, is now available from bookshops and from Amazon.
A diary written using a numerical code in a prisoner of war camp in 1941/2 should not be too difficult to decode, should it?
Hong Kong, 1941. On December 8 1941, the Japanese attacked Hong Kong. Seventeen days later, on Christmas day, the brave but outnumbered defending forces surrendered and were put into prisoner of war camps in which many died. A young squadron leader in the RAF, Donald Hill, kept a diary of events during the battle for Hong Kong and for a while during his captivity. In order to keep it secret, he wrote it in a numerical code which, according to the cover of the book in which he wrote, was supposedly ``Russels Mathematical Tables''. Donald survived the camp and brought the diary out with him. However, his experiences were so traumatic that he did not like to talk about them. The diary was never translated before his death in 1985.
Guildford, 1996. The phone rings again. The secretary in the Department of Mathematical and Computing Sciences, University of Surrey answers it, polite as always. The caller, Col Ian Quayle of the Soldiers, Sailors and Airmen's Families Association, asks to speak to a mathematician. Having just finished some photocopying, I happen to be the nearest person to the phone so the secretary asks if I will deal with the call. Col Quayle explains about Donald Hill's diary. Mrs Pamela Hill, Donald's widow, is keen to have the diary decoded so that she can find out more about a closed chapter in his life. I suggest that he sends a copy of the diary and say that I will have a look at it.
The Diary. The first page described how the `Tables' could be used for multiplication. Instructions for multiplying 83 by 26 were given which could be followed on the first page of numbers. However, the claimed answer of 2118 was clearly incorrect. This presumably was part of the disguise.
Twelve pages filled with numbers followed. On each page there were approximately 57 rows and 25 columns with 4 digits in each column. On the first two pages, the sequence of digits could be expressed in terms of the numbers 1-26, with a dot being placed either side of a single digit number. On subsequent pages the numbers 10-35 were used which fitted more conveniently into the columns (see Fig. 1). This was a good first indication that this really was a code and not mathematical tables.
Getting Started. A research career in bifurcation theory and chaos is not the best background for tackling a problem in cryptography. However, a code written over 50 years ago and in a prisoner of war camp could not be too sophisticated and, with a little help from a computer, should not be too difficult to crack even for a novice, or so I reasoned.
First stop was the University library and I was soon browsing through some old books on cryptography, learning the basic methods. A substitution cipher seemed an obvious method, in which each number represents a letter and it is simply a question of matching each number with the right letter.
The frequency of letters occurring in a long piece of text has a characteristic pattern. The ordering of letters, with the most frequent first, is always similar to 
By generating a frequency list for the numbers in the diary and comparing with this list, it should be possible to match numbers with letters. So I hurried off to my computer, typed in the first page of numbers and wrote a little program to determine the frequency of each number. Setting 1=A, 2=B, etc., the ordering derived from this first page was
With the first nine letters of the two lists in the same order, and only minor variations thereafter, the only conclusion was that there was a direct translation of numbers to letters with no change of ordering. This also confirmed that the numbers did correspond in some way to text but that the method used was not a substitution cipher.
What Next? Now that the translation of numbers into letters had been determined, the next question was how should the letters be rearranged to give meaningful text. The number of possible ways in which such a transposition cipher could be done made the problem seem a little less easy than my early optimism had lead me to believe. So I returned to the pages of the diary looking for more clues. There was very little in the way of markings on any of the pages apart from the first. However, the following observations invited further investigation.
The first six are all successive multiples of 34 but after that, the following two increments are only 33. However, this suggested that the letters should be put in rows of 34, and this seemed to link in with the right hand arrow with the number 340 next to it. When I did this, the first marker of four zeros occurred after exactly 33 lines, which also gave meaning to the down arrow with the number 330. It did not take long to then confirm that there were 1122 (=34x33) letters between each marker of four zeros. Thus it seemed that the letters should be written out in blocks with 34 columns and 33 rows. A second important step of progress had been made, but there was still no story to be read.
Digraphs. With all the letters now arranged in blocks, some sort of rearrangement of the letters into text was required. But how? One approach was to search for digraphs (pairs of letters). In a long piece of text, the frequency of adjacent pairs of letters can also be determined and again has a characteristic pattern. The most frequent digraphs are TH and HE . So I took the blocks, paired letters in several different ways and counted the frequency of the pairs, hoping that if I got the combination right, the pairs TH and HE would appear at the top of the frequency list. But nothing that I tried seemed quite right. Another approach was to take each letter T and determine the position of every H in a block relative to the T and add up frequencies of positions, hoping to find the relative position where H occurred most frequently. However, this method did not give consistent results either. Another idea was to check for the first letter of a pair in the first block and the second letter in the second block. Still no joy. One problem with using a computer to check for patterns is that it is best when checking for regular patterns, which had brought no success. It is not so easy to check for irregular patterns.
Keywords. It was time to go back to the diary and look for more clues. I tried to find some hints from the instructions on the first page about how to use the `Tables' for multiplication but could find nothing there. Also on the front page, at the bottom, was written the two names
Did these have any significance? Then, lying awake in bed early one morning, it suddenly occurred to me to count the number of letters in the names - 34! It must be that these names were used as a keyword to rearrange the columns of each block, another standard method . Text written out in block form can be rearranged by changing the order of the columns. The keyword is written over the columns in a block which are then reordered so that the letters in the keyword are in alphabetical order. Reversing the process is simple provided that the keyword is known. Well, it seemed like a good idea until I was again staring at lots of jumbled letters. Still, I was convinced that it was no accident that there were 34 letters in these names and that I had just made a third important step forward.
I was sure that I was now close to deciphering the code. However, time was running out and a new semester with a busy teaching schedule was looming.
Fig. 2: Donald and Pamela on their wedding day in 1946
The Final Step. I returned to the diary and pored over the pages, looking for any small clue that might provide more information. On some of the early pages, some numbers had been ringed. Often these were so faint as to be hardly visible. For each one, I counted the number of characters from the beginning of its block. Some of the positions were
which are all multiples of 33. This indicated that the letters should be divided into groups of 33 and not 34 as I had been doing. So I tried filling up each block by putting groups of 33 letters in columns rather than 34 letters in rows as I had done previously. I then ran my program to rearrange the 34 columns using the keyword made up of the names and looked at the output. There on the screen in front of me I saw the words `war' and `Japan'. I suddenly realised that I was looking at text which I could read! I sat there for a moment, hardly believing that I had at last cracked this `simple' code.
Translation. I quickly translated the first few blocks of numbers which I had already put on the computer. I had to put in spaces between words and full stops were marked by an `x'. (Note that the letter `x' is two places higher up the frequency list from the diary compared with the standard list because of this.) The unfolding story was gripping. I borrowed a computer to take home so that I could type in more numbers during the evenings and then brought the disk in to work in the mornings, impatient to read the next chapter of the story. Finally the task was complete, and in 11 pages, a fascinating story of life in war torn Hong Kong and as a prisoner of war was revealed for the first time in 55 years.
The work did not quite end there though. The last page of the diary contained an incomplete block. Because of the way it had been written, when this partial block was translated, it gave text with letters and blanks intermingled. Could the gaps be filled in to reveal more of the story? It is very difficult to guess at words which are incomplete. However, there was a dictionary on the computer that could be searched for particular strings which could include wildcards for the missing letters. This provided a very effective, systematic method for filling in the blanks. Some parts came together easily while others took more time but eventually, the gaps were filled in and the story told.
The Family. Mrs Hill was very pleased to have the diary translated after so many years. She said that reading it was like finding the missing jigsaw piece in her husband's life.
Afterthoughts. The names on the front page and the boxes around the numbers on the first page were done by Donald when he once tried to show his son Christopher how to translate the diary. However, since he put a box around every 34th letter rather than every 33rd, he clearly could not quite remember exactly how to translate it. The two names which make up the keyword are of course his own name and the name of his then fiancee Pamela.
What Did It Say? The diary told the story of the battle for Hong Kong and of life in the Sham Shui Po camp during the period December 7 1941 to March 31 1942. Some extracts are as follows.
December 23rd. Up early, lucky for me, as a bomb lands on my bed just as I leave the room wrecking everything including my kit.
December 25th. What a Christmas day, empty stomachs, tired out, and heaven knows what is going on. At ten am a message arrives saying their is a truce until midday. This news is immediately followed by a terrific bombardment of our positions. Not my idea of a truce.
December 26th. Several (Japanese) officers started arguing and kept pointing at me and looking aggressive. Suddenly one of the officers whipped out his sword and I thought they had decided to bump me off but to my amazement he produced a bottle of beer, nipped the top off with his sword, and handed me the bottle. I was then given a loaf of bread. Two officers decide to drive me back in a Ford Ten. They don't use any lights and we have several narrow escapes from hitting lamp posts. Suddenly I see we are heading for one of the islands in the middle of the road and shout a warning. Too late and there's a terrific crash and we finish up on our backs. By now I am fed up so, bowing politely, I leave them and walk the two miles to China Command.
December 30th. It would appear that we are going to Sham Shui Po. The whole camp has been stripped of every useful article by looters and had also been bombed. All doors, windows, furniture, and fittings had been taken leaving just hulks of buildings. Even in peace time it was an awful dump, but now it looked as if a typhoon had hit it.
December 31st. There are over six thousand men in the camp with no sanitation and rotten food. We have no lights and go to bed soon after dusk. We have one meal at nine and another at five consisting of soggy rice and are permanently hungry. And so ended nineteen forty one.
February 6th. Spend hours these days thinking of home and family, especially Pam. They probably think I am dead and I pray to God that the Japs will get news through. Thank God for you Pammy darling, your memory is ever with me. I still have your photograph, signet ring and cigarette case. I will never lose them.
 R.A. Haldane, The Hidden World, Hale, London, 1976.
 A. Sinkov, Elementary Cryptanalysis: A Mathematical Approach, Random House, 1968.
© P.J. Aston, 1997.
The text of the diary is also available.
This article first appeared in the October 1997 issue of Mathematics Today , published by the Institute of Mathematics and Its Applications .
Another version of this story can be found on the PASS Maths pages.
Mathematics Research Homepage