Diana cipher wheel

During the Vietnam War "clandestine" communication between US military forces was based on the Diana Cryptosystem. This methode to encode en decode messages
is theoretically unbreakable when used properly. The cryptographic cipher is
based on two techniques.
First of all, it uses a trigraph to convert two letters into a third letter.
This conversion uses a fixed lookup table — an example of which is pictured on the left — that maps each combination of two letters (blue & green into a third red letter.
What is specific about this conversion is that for each triplet of letters it
holds that any two letters of the triplet are always converted into the third
letter of the triplet. For example, if it is given that the letters B and K are
converted in the letter O, then we also know that the letters K and B yield the
letter O, and also that the letters O and B yield the letter K, and that the
letters K and B yield the letter O. Actually, it is quite easy to compute the
conversion. If we find the two given letters in the alphabet at positions and
(where A is at position 0, B is at position 1, and so on), then we find the
third letter in the alphabet at position, where the operator represents the
remainder after integer division.
Home made Diana cipher wheel. Using wooden disks 18cm and 15cm bought from Lazada (80bht). Created two images with the alphabet, had them printed on 260gr paper. To determine the centre and drill a hole you need to be very meticulous. I used a paper template with a second and third circle of letters to find the right spot to cut the window in the second disk.
Second technique of the Diana cipher is the use of one-time pads. There were only two matching pads in existence and they would only be used one time. There were booklets that contained randomly generated groups of 5-letter words, 30
words to a page. The person sending a message would first write the letters to the message, over these random groups of
words. Included in the front of each one-time pad was a one-page encryption table. If I wanted to send the letter P,
and the letter under the P was an A, then I would send a K. The person listening on the frequency at the other end,
would have the other matching pad. They would write the letter they received (a K) over the letter in their one-time
pad (an A), and decipher it based on the table, yielding the original letter P.
Each communication site in Vietnam (we had over 100 A-Camps along the Cambodian / Laotian border, and some 20 B-detachment sites spread over the country) had a different pad, depending on the location they were having the commo-check with. It obviously was very important that both people were using the appropriate matching pads, or the deciphered messages would not make any sense.
After a while, most of us became so proficient with the system, that we actually learned the deciphering matrix by heart. No matter what pads anyone had, the combinations always were the same. i.e. Any 3 letters always went together, regardless of the order; BKO/KOB/OBK/BOK. After listening to thousands and thousands of transmissions, it really got quite simple.
Diana cipher simulated in C.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
void usage(int nr, char *arg[]) {
for (int i=0; i < nr; i++) {
printf("%s ", arg[i]);
}
printf("%d\n", nr);
printf("\nusage: ./diana -k key -[c|m] [msg|code]\n");
exit(1);
}
int main(int argc,char *argv[]) {
unsigned char key[100]={'\0'};
unsigned char msg[100]={'\0'};;
unsigned char code[100];
unsigned char k,m;
unsigned int i,y = 0;
unsigned int keystart,keyend,keylen;
if (argc < 5) {
usage(argc,argv);
}
for (i=1; i < argc; i++) {
if (strcmp(argv[i], "-k") == 0) {
keystart = i+1;
} else if ((strcmp(argv[i], "-m") == 0) || (strcmp(argv[i], "-c") == 0)) {
keyend = i;
}
}
for (i=keystart; i < keyend; i++) {
strcat(key,argv[i]);
}
keylen=strlen(key);
for (i=keyend+1; i < argc; i++) {
strcat(msg,argv[i]);
}
for (i=0; i < strlen(msg); i++) {
if (y >= keylen) y = 0;
k = toupper(key[y]);
m = toupper(msg[i]); // k + M + C = 220 or 246
if ((220 - k - m) < 65) code[i]=246 - k - m;
else code[i] = 220 - k - m;
y++;
}
code[i]='\0';
printf("%s\n",code);
return 0;
}