/*---------------------------------------------------------*/ /* */ /* PKE Demo program header by D. Canright */ /* */ /*---------------------------------------------------------*/ #include #include #define Uses_TApplication #define Uses_TCheckBoxes #define Uses_TMenuBar #define Uses_TStatusLine #define Uses_TRect #define Uses_TDialog #define Uses_TInputLine #define Uses_TLabel #define Uses_TScroller #define Uses_TScrollBar #define Uses_TWindow #define Uses_Boolean #include const int MAXSIZE = 81; const int MAXSSIZE = 127; const cmOpenKeyWin = 201, cmNewKeyWin = 202, cmSaveKeyWin = 203, cmOpenMsgWin = 204, cmNewMsgWin = 205, cmSaveMsgWin = 206, cmEncrMsgWin = 207, cmDecrMsgWin = 208, cmDbEnMsgWin = 209, cmDbDeMsgWin = 210, cmCopyKey = 211, cmPastePriKey= 212, cmPastePubKey= 213, cmEncrFile = 214, cmDecrFile = 215, cmDbEnFile = 216, cmDbDeFile = 217, cmDoHelp = 218, cmDoHelpMath = 219, cmDoHelpAbout= 220; const int maxLineLength = maxViewWidth+1; const int maxLines = 500; const int numWidth = 8; const int numLength = 6; const int msgWidth = 36; const int nameWidth = 12; const int unknownint = 0X8000; class TNumIn: public TInputLine // define a new window class { public: TNumIn( const TRect& r, short aNumber = numLength ); virtual void handleEvent( TEvent& Event ); void setData( int z ); int getData(); }; class TInterior : public TScroller { int lineCount; char *lines[maxLines]; public: TInterior( const TRect& bounds, TScrollBar *aHScrollBar, TScrollBar *aVScrollBar, const char *fileName ); // constructor virtual ~TInterior(); virtual void draw(); // override TView::draw void readFile( const char *fileName ); void deleteFile(); }; class THelpWindow : public TWindow // define a new window class { public: THelpWindow( const TRect& bounds, const char *aTitle, const char *fileName ); }; class PKEApp : public TApplication { THelpWindow *helpWin[3]; ushort kwinNum, mwinNum; public: PKEApp(); virtual ~PKEApp(); virtual void handleEvent( TEvent& Event ); static TMenuBar *initMenuBar( TRect ); static TStatusLine *initStatusLine( TRect ); virtual void outOfMemory(); void newMsgWin(const char *fileName); void newKeyWin(const char *fileName); void keyfileOpen(); void msgfileOpen(); void doSuspend(); void doResume(); void doHelp(int type, const char *aTitle, const char *fileName); void encryptFile(); void decryptFile(); void dblencryptFile(); void dbldecryptFile(); int clipPriv, clipPub, clipMod; }; class TKeyWindow : public TDialog // define a new window class { int pub, priv, modulus; // keys TNumIn *publn, *privln, *modln; public: PKEApp *boss; TKeyWindow( const TRect& bounds, const char *aTitle, PKEApp *theBoss ); virtual void handleEvent( TEvent& Event ); int readFile( const char *fileName ); void writeFile(); int generate(); private: void writeKeys(); void clipKeys(); }; class TMsgWindow : public TDialog // define a new window class { char msg[MAXSIZE], secret[MAXSSIZE]; TInputLine *msgln, *secretln; public: PKEApp *boss; TMsgWindow( const TRect& bounds, const char *aTitle, PKEApp *theBoss ); virtual void handleEvent( TEvent& Event ); int readFile( const char *fileName ); void writeFile(); void encrypt(); void decrypt(); void dblencrypt(); void dbldecrypt(); private: void getMsgs(); void putMsgs(); }; class TKeyDialog : public TDialog // define a new window class { public: PKEApp *boss; TInputLine *keyin, *modin; TKeyDialog( const char *aTitle, int theMod, PKEApp *theBoss ); virtual void handleEvent( TEvent& Event ); private: int mod; }; // for error messages: extern char errorMsg[]; extern ostrstream errstr; extern char buf[]; // all-purpose line buffer ushort execDialog( TDialog *d, void *data );