                  SOLVING VIGENERE CRYPTOGRAMS
                 (Text in ISO text format; for
                  old MSDOS format see readme.txt)

The Vigenre cipher was of the most popular methods of encoding 
secret texts until the beginning of this century. It employs an 
alphabetical key which is repeated. The plaintext is added to the 
repeated key to produce the ciphertext:

key ->                  PANCAKEPANCAKEPANCAKEPANK
plaintext ->            THISMESSAGEISCONFIDENTIAL
                        ------------------------- +
ciphertext ->           IHVUMOWHATGICGDNSKDORIINN

(by 'adding' is meant: number the letters so that A = 0, B = 1,..
, Z = 25, add the numbers, convert the result back to letters. If 
the addition yields a number higher than 25, subtract 26 first).  

Legitimate decoding (for which the recipient needs to be in 
possession of the correct key) is the reverse of this process.

Although this has been considered an 'unbreakable' cipher during 
much of history, it is in fact not a tough cipher at all. Because 
the key is of finite length and is repeating, repeated patterns 
can always be found in the ciphertext. From these the keylength 
can be established. Then the letters of the ciphertext are taken 
at intervals of one keylength and letter frequencies noted. The 
keyletters can then be found, and the plaintext reconstructed, on 
the basis of letter frequencies in the underlying language of the 
plaintext. The whole process can be readily automated. This is 
what the enclosed program vigenere.c does. The algorithm is based 
on one found in Caxton C. Foster, "Cryptanalysis for 
Microcomputers", Hayden Book Company Inc, Hayden, Massachusetts, 
1982. 

To use, compile vigenere.c first. A file called standard.frq, 
containing letter frequencies for the language concerned, must 
also be present on the disk (in this package, standard.frq is for 
English; there are also frequency files for two different 
spelling variants of Dutch). In many cases (and certainly with 
long cryptograms) the English letter frequencies will also work 
in other west-European languages.

Your ciphertext is in a text file called "cipher.txt", say. Then 
simply call:

vigenere cipher.txt

and with any luck the plaintext will appear on your screen.

vigenere has one option: -p. If you type

vigenere -p cipher.txt

you will be prompted for the keylength and keyword. For short 
cryptograms it may be necessary to choose a keylength which is a 
submultiple (one half or a third) or a multiple of the length 
suggested by the program. 

Output of vigenere is to standard output; it can be redirected to 
a file or "piped" into another program (this works under Unix and 
ms-dos). With the -p option, input can also come from standard 
input; in that case vigenere operates like a Unix-style filter. 


Auxiliary programs
==================

vigenc.c: encode texts into Vigenre. 
Usage: vigenc <keyword> <plaintext>

vigdec.c: "legally" decode texts from Vigenre (you need to have 
the keyword).
Usage: vigdec <keyword> <ciphertext>

Both programs can also be used as filters; e.g. under Unix:

cat plain.txt | vigenc pancake > cipher.txt

will encode plain.txt using the keyword "pancake" and write the 
result to cipher.txt (in ms-dos, you would use "type" instead of 
"cat"). 

fives.c: group texts into groups of five uppercase letters. All 
non-letters are discarded apart from asterisks (see below). fives 
is a filter, so you can for instance type

vigenc pancake plain.txt | fives > cipher.txt

to produce "professional" looking ciphertexts.

In all the programs in this package, asterisks can be used to 
indicate "illegible letters". That is, an asterisk in the input 
becomes an asterisk in the output, but it does advance the internal
counters for the purpose of grouping and of Vigenre encoding/
decoding. 


A cryptogram of some human interest
===================================

I made the vigenere program years ago at the request of a friend. 
He wanted to crack a mysterious ciphertext which he had found 
engraved upon an old tomb in Pacitan, on the south coast of the 
island of Java in Indonesia. Of course we hoped for a solution of 
the type "a large pot of gold is buried twenty paces west of this 
tomb". In reality, the text revealed a rather sad story, as the 
reader will discover after cracking the text using this program. 
The plaintext is in Dutch; full details of the story are given in 
the following two articles in "Archipel" (a magazine published in 
France, devoted to the history, language, and culture of South-
East Asia):

Une mystrieuse pitaphe  Pacitan, by Henri Chambert-Loir & 
Claude Guillot, Archipel, summer 1994

The grave at Pacitan, by dr. W. Remmelink, Archipel, summer 1995
  
The text on the tomb is as follows. Asterisks denote damaged or 
missing letters. The punctuation, which is also present in the 
original, is ignored by the program, and will not appear in the 
output.

ZSGJXFXFMFBDFWEF
DXWBUJHRVWWGZEBG-
ZZ.ZBAGKBMAGXBZMQ-
HWGENFWBQVWOHWXK
YWOBMLBDNNXOKWWBM
VXKSOTXKXWBMVXZD-
EUBQFXDDFMFDFALM
VXOCWGBDF
HJXFWGZEBGZZFVMJ
HLRNTKRSKLMZHBLG
XQHCNJXFXIHWYADWG
ENGZXBZMFMYUBSMB-
DDF?WBGWXIDOXODDW
FRERAZSKQNWMBJDX
FMRTIHCNLNAMT*VX-
OYAXK?ZDLBQWXKKW 
OBMALEHWKKZETXKK
**DLZVSZTKRAGE**
**QSWVRRRKFQPXZJM
**GZLDVXKVWKAYGH*
*LORHDZBFGHFCVT
**GF.FJRTICWGJNWB
**CXKVWZLUWKDNDZ-
LSZTKDEXKDFNTDWK
QDJNDUAGADF.MLSOX-
ADJSFDFL!

15 october 1997
Jan W. Stumpel <jstumpel@planet.nl>
Oegstgeest, The Netherlands

