[net.crypt] cryptanalysis puzzle

reeds@alice.UUCP (Jim Reeds) (04/17/84)

[Burnt Njal lives!]

Here is a cryptanalysis puzzle with a (small, but interesting) real-world
application.  The enemy is known to encipher data files with a routine
"encipher", whose source code is reproduced below.  Each file recieves its
own keys:  the byte "key1" and the two byte arrays "key2[]" and "key3[]".  
Each file is about 100,000 bytes long, and the two key arrays are of unknown
length.  One supposes, however, from study of predecessor systems that the 
key arrays are of length about 100 or 200.  Each file contains a lot of ascii 
text data, a lot of of NULL characters, with the rest binary data, in the 
proportions 40%, 30%, 30%.  Files come in triplets.  Each file in a triplet
has its own key data, but files in a triplet differ in about 10% of their
bytes.

The problem: to write an automatic cryptanalysis program that accepts a triplet
of files as input and produces their corresponding keys as output.

I have started working on this yet but cannot imagine it is very hard.

					Jim Reeds
					201 582 7066
					alice!reeds

	#include <stdio.h>

	extern char key1, key2[], key3[];

	/*
	 * encipher and write output
	 * n: number of bytes to be enciphered
	 * s: starting address of plain text
	 * p: stdio stream to write onto
	 * key1, key2[], key3[]: key data (globals)
	 */
	encipher(s, n, p)
	register char *s;
	FILE *p;
	{
		register char *a = key2;
		register char *b = key3;
		char byte = key1;

		while(n--) {
			putc(*s++ ^ *a ^ *b ^ byte , p);
			byte += *a++ * *b++;
			if(! *a) a = key2;
			if(! *b) b = key3;
		}
	}