Civil War Signaling Related C Programs
by Lee A. Taylor
This web page contains a description of and links to several programs for those interested in exploring further the nature of the signaling and encryption of the Civil War. The description here is fairly complete, even though not all of the programs have been written yet. All of the programs are written in C for Borland's Turbo C++ ver. 4.5 (but should work with most other C compilers). There are executables at the bottom if you don't care about the source code that will make and break encrypted messages for you.
The first program, encoder.c, takes as its only argument a file containing a text message (which you can create with NotePad or any other text editor) and converts it to the flag waves corresponding to the June 1861 wig-wag code. You can put multiple text messages to be encoded on separate lines in the file and, if all goes well, each one will be encoded as a separate message (i.e., there should be a 333 at the end of each output line). I think this program handles the common word endings and preconcerted codes correctly, but I haven't tested it exhaustively.
Click here to get the C source code for encoder.c. (If you're very brave and trust me, click here for encoder.exe, which you don't have to compile yourself to get it to run.)
The second program, decoder.c, takes as its only argument a file containing flag waves that contain strings of the characters 1, 2, 3 and P (for pause) and converts the flag waves back to the original message.
Click here to get the C source code for decoder.c. (If you're very brave and trust me, click here for decoder.exe, which you don't have to compile yourself to get it to run.)
The next program, probs.c, produces two C arrays of monographic and digraphic probabilities that are needed in the attack programs below. The output of this program, should you wish to recompile and make new tables of probabilities to be used with the programs below, should be placed in a file called probs.h before compiling the programs below.
Click here for the C source code for probs.c (and click here for probs.exe). Click here if you’d like the copy of probs.h that I created with a large corpus of plain text.
The next program, codebrk.c, attempts to recover the correspondence between the flag waves and the letters of the alphabet. More details on this one later…
The next program, encrypt.c, takes a file containing a key phrase and multiple messages and outputs the encrypted form of each message. If you would like to combine this with encoder, you can take an output message from this program and get the flag waves necessary to transmit this message.
The next to last program, decrypt.c, takes a file containing the key phrase and multiple ENCRYPTED messages and decrypts the messages, outputting the plaintext messages.
The final program, cryptbrk.c, attempts to recover the key phrase used to encrypt the messages given in an input file. If you don't put multiple encrypted messages in the input file, then the program is unlikely to recover too much (if any) of the key phrase. This program will (someday) also have the ability for you to tell it some of the characters of the key phrase and run it again to see if it can recover more of the key phrase.
Here's a brief diagram that shows how these programs could be used in a "real life" scenario (of course, during the War for Southern Independence, there were no computer programs to do all the work!):
ORIGINAL MESSAGE --> encrypt --> encoder --> FLAG MAN -->
FLAG READER --> decoder --> decrypt --> ORIGINAL MESSAGE
If you're not the intended recipient (and, therefore, don't know the key phrase), the second line would be
FLAG READER --> decoder --> cryptbrk --> decrypt --> ORIGINAL MESSAGE
but you'd have to get multiple messages before going on to the decrypt part, since cryptbrk won't figure out the key phrase for you with just one message (at least it's not very likely).
HAVE FUN!
Just the Programs
The programs below can be used to encrypt messages (the first program) and to break and decrypt messages (the second program). Caveats for usage:- to run the encrypter type "encrypter key plaintext-filename" where 'key' is the key phrase you wish to use, all upper case letter, no spaces, numbers or punctuation; and 'plaintext-filename' is the name of a file containing the text you wish to encrypt. It will only encrypt alphabetic characters and will only do up to 5000 characters for now.
- to run the code breaker, type "solver ciphertext-filename" where 'ciphertext-filename' is the name of a file containing the encrypted text. It will only use 5000 characters (if the text is decent, this should be more than enough, unless the key used to encrypt was REALLY long). Note, if you don't have enough cipher text in relation to the length of the key, this attack won't work very well (a 25-to-1 ratio is in the ballpark of the minimum message length you need).
Right-click and do "Save Target As..." here to get the encrypter.
Right-click and do "Save Target As..." here to get the solver.