/*
 *	Checker Class
 *	By Jeremy Lennert
 *	February 8, 2001
 *	v. 1.1
 *
 *	Checker.h
 *
 *	Class definition for checker class, used to run various heuristical
 *	tests upon ciphertext and candidate plaintext by the Decrypter program.
 */

#ifndef Checker_h
#define Checker_h

#include "Keys.h"
#include "FreqTable.h"

typedef struct _candidate{		// Stores a key-score pair
	Keys *key;
	double score;
} candid;

class Checker
{
public:
	Checker(FreqTable *lnfreq);

	double check(unsigned char *plaintext, Keys *key);	// Runs standard test
	double quick(unsigned char *plaintext, Keys *key);	// Runs fast tests to try to eliminate
												// candidate easily
	double thorough(unsigned char *plaintext, Keys *key);	// Runs a thorough test
	double score(unsigned char *plaintext, Keys *key);	// Gets a score, but doesn't remember
														// key even if score is best so far
	double coincidence(unsigned char *text);	// Runs an index of coincidence test
	const candid Best();	// Reports the key and score of the best candidate so far
	void reset();	// Reset score and forget best key
protected:
	candid best;	// Key with best score so far, and its score
	FreqTable *lnf;	// Natural logs of expected frequencies
	FreqTable *freq;	// Observed frequencies in text

	int compare(candid test);	// Checks if the latest score is better than the best,
								// if so, it records the new best
};

#endif