/*
 *	Lorenz SZ 40 Emulator
 *
 *	- Copyright 1997 Jim Bumgardner jbum@thePalace.com
 *
 *	See tunny.c for comments.
 */

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define MACINTOSH		1		// Turn off if not compiled on a Mac

#if MACINTOSH
#ifdef __MWERKS__
#include <SIOUX.h>              /* Metrowerks needs this */
#include <console.h>			/* ... and this */
#endif
#ifdef THINK_C
#include <console.h>			/* Think declares it here */
#endif
#endif


#define MaxWheelLength		64
#define MaxTextLength		256

enum {Chi41,Chi31,Chi29,Chi26,Chi23,
	  Psi43,Psi47,Psi51,Psi53,Psi59,M37,M61,NbrWheels};


typedef struct {
	char	pins[MaxWheelLength];
	int		length;
	int		startingPosition;
	int		position; // 0 --> length-1
} Wheel;

typedef struct {
	Wheel	wheels[NbrWheels];
} TunnyMachine;


extern TunnyMachine	gTM;

// Function Templates
void MySRand(long s);
void Randomize(void);
long LongRandom(void);
double DoubleRandom(void);
int MyRandom(short max);
void ResetTunnyMachine();
void InitWheel(int wheelNbr, int length);
void ResetWheel(int wheelNbr);
int GetWheelPin(int wheelNbr);
void RotateWheel(int wheelNbr);
void RandomizeWheel(int wheelNbr);
void RotateTunnyMachine();
void InitTunnyMachine();
void SetTunnyKey(long key);
void EncodeCipher(char *inStr,char *outStr,int len);
void DisplayTunnyString(char *prefix, char *tunnyStr, int len);
void ConvertStringToPlainText(char *str, char *tunnyStr, int *len);


