⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enigma4j.c

📁 ENIGMA3模拟WW II加密算法(含EXE文件)
💻 C
📖 第 1 页 / 共 5 页
字号:

/***************************************************************************/

/* ENIGMA4.C  A simulator for the WW II cryptographic engine ENIGMA        */
/*            (3 Rotor Version)                                            */

/* USAGE:     enigma [-cdt]                                                 */

/*            -c simulate a green cover over the lamps                     */
/*            -d show aditional information (what knows ENIGMA about the   */
/*               system it is running on, tracing information during       */
/*               encoding)                                                 */
/*            -t show the last encoded characters                          */ 

/* KEYS:      Some keys can be used alternate to the standart ones         */

/*            UpArrow:     Cntrl-P                                         */
/*            DownArrow:   Cntrl-N                                         */
/*            LeftArrow:   Cntrl-B                                         */
/*            RightArrow:  Cntrl-F                                         */

/*            F1:          1                                               */

/* SWITCHES: some #define's change the behaviour of ENIGMA                 */

/*            ATARI_ST          ENIGMA assumes it is running on an         */
/*                              Atari ST, VT52 is used                     */
/*            MSDOS, __MSDOS__  ENIGMA assumes it is running on a PC       */
/*            __GNUC__          test() says "compiled with Gnu C"          */
/*            MSDOSBW           On PC: black & white, uses ANSI.SYS        */
/*                              else:  inverse to default vt100            */
/*            VT320             *** Never use this one on a PC! ****       */
/*                              It uses some special ESC Sequences         */
/*                              unknown to ANSI.SYS. It might help if      */
/*                              cls() doesn't work on vt100 terminals.     */
/*                              I'm not sure if this Sequences are vt100.  */
/*                              I found them in a manual for a vt320       */
/*                              terminal                                   */
/*            VT52              use vt52 Graphics                          */
/*            CURSES            should be defined when getch() has to be   */
/*                              imported from the curses library           */
/*                              does minimal initialisation, but no        */ 
/*                              keypad(), no use of curses for output      */
/*            SWEARWORDS        use curses for output, too                 */
/*                              (includes CURSES)                          */
/*                              uses keypad() for input, this means F1 and */
/*                              cursor keys will be correctly recognized   */
/*                              without the need to know the scan codes    */
/*            BSDCURSES         don't use System V specific curses routines*/
/*                              (includes SWEARWORDS, but puts             */
/*                              restrictions on it)                        */
/*                              no keypad()                                */
/*            UNIX              test() says "compiled for UNIX"            */
/*            SUN               for SUN Workstations,                      */
/*                              uses CntrlL ('\014') for cls()             */
/*            NEEDSCR           defines puts(s) as printf("%s\r\n",s)      */

/*            DEBUG             You get a lot of strange messages.Not for  */
/*                              normal use                                 */

/*            These are set automatically:                                 */

/*            COLOUR            indicates that the system can display      */
/*                              colours. At the moment only with MSDOS     */
/*            VT                use vt100                                  */

/*            ANSI_COL          use ANSI.SYS for colours                   */

/* (c) 1994   by Andreas G. Lessig,Hamburg                                 */

/*            I don't care if you distribute this program, but carefully   */
/*            mark all changes in the source. Make certain that everybody  */
/*            knows (s)he is using a version you altered.                  */

/*            If you find a way to make money out of this program that's   */
/*            o.k. with me, but I want my share. So please contact me      */
/*            before using it comercially. I'm sure we'll come to an       */
/*            agreement. My Email-adress is                                */
/*                  1lessig@rzdspc1.informatik.uni-hamburg.de              */

/*            This program comes "as is". There is no implied warranty.    */
/*            You try it at own risk. If it doesn't work or trashes your   */
/*            system I won't pay. ( This doesn't mean I wouldn't answer    */
/*            questions, but I definitly won't pay ...)                    */

/*            Suggestions are welcome.                                     */


/*            Ich habe nichts gegen eine Weitergabe des Programms, aber    */
/*            jegliche kommerzielle Verwendung ist vorher mit mir          */
/*            abzusprechen.                                                */
  
/*            Ver"anderte Programmversionen sind zu kennzeichnen.          */

/*            F"ur Anregungen bin ich dankbar                              */

/* ENIGMA1.C                                                               */
/* 19.12.1994 Mock up, d.h. blo"s ein graphisches Interface, aber es wird  */
/*            nicht chiffriert                                             */
/*            gedr"uckte Tasten werden invertiert, zugeh"orige L"ampchen   */
/*               leuchten                                                  */
/* 21.12.1994 Verdrahtung von Rotoren und Reflektoren #define'd            */
/*            Variablen f"ur die Einstellungen                             */
/*            Rotoren,Reflektor,Steckerbrett verschl"usseln                */
/*            Rotoren drehen noch nicht, k"onnen aber mit den Pfeiltasten  */
/*               manuell verstellt werden                                  */
/*            Grundeinstellung kann noch nicht editiert werden             */
/* 27.12.1994 Rotoren drehen jetzt, es wird zwischen der Stellung des      */
/*            Ringes und der der Verdrahtung unterschieden                 */
/* 28.12.1994 Rotoren und der Reflektor k"onnen ausgew"ahlt werden         */
/*            Das Steckerbrett kann editiert werden.                       */
/*            Die Ringstellung kann noch nicht ver"andert werden           */
/* 30.12.1994 Codes f"ur die benutzten Tasten #define'd                    */
/*            Tastatur entsprechend dem Original berichtigt                */
/*            Codes f"ur Sonderzeichen als #define                         */
/*            Allgemeines Facelifting                                      */

/* ENIGMA2.C                                                               */
/*   4.1.1995 gr_init(): Dummyfunktion, bei Portierung u.U. n"otig,um      */
/*                       die Graphik zu initialisieren     */
/*            Variable f"ur den Rotortyp                                   */
/*            Eingabe der Rotoren "uberarbeitet -> askrotor()              */
/*            Variable f"ur den Reflektortyp                               */
/*            Ringstellung implementiert                                   */
/*            Eingabe des Steckerbrettes gegen Fehlbedienung abgesichert   */
/*            Im Setup Ausgabe der gegenw"artigen Einstellungen            */

/* ENIGMA3.C                                                               */
/*   4.1.1995 Erster Versuch Enigma portabel zu machen                     */
/*            neue define's:                                               */
/*               VT       vt100 benutzen                                   */
/*               COLOUR   Farbdarstellung                                  */
/*               MSDOSBW  vt100 unter DOS                                  */
/*               DOSGCC   Farbdarstellung unter DOS mittels gcc Library    */
/*               ANSI     dito, aber mittels ANSI.SYS                      */
/*            neue Farbdefinitionen f"ur s/w                               */
/*            Sonderzeichen f"ur portable Version neu                      */
/*            F"ur ANSI und vt100:                                         */
/*                                                                         */
/*               ScrenPutChar(),ScrenSetCursor()                           */
/*            Tasten: 1 alternativ f"ur F1                                 */
/*                    CntrlP f. UpArrw                                     */
/*                    CntrlN f. DwnArrw                                    */
/*                    CntrlF f. RghtArrw                                   */
/*                    CntrlB f. LftArrw                                    */

/*            Noch ein Bug beim Einstellen der Ringstellung:               */
/*            wenn window[n]!='a' gibt es M"ull                            */
/*   5.1.1995 Stellen zum Einsatz sp"aterer Routinen f"ur andere Systeme   */
/*            markiert                                                     */
/*            obigen Bug hoffentlich behoben                               */
/*            ScreenPutChar gibt Zeichen > 127 nur aus, wenn MSDOS         */
/*            definiert ist                                                */

/* ENIGMA4.C (international version)                                       */
/*   5.1.1995 English description/legal notice in header                   */
/*   6.1.1995 added initscr() followed by refresh()  if the CURSES switch  */
/*               is set. Needed it under UNIX. These, and getch() are the  */
/*               only functions I use from curses. The rest is vt100.      */
/*            added switch VT320 for use of not ANSI- compatible ESC       */
/*               sequences                                                 */
/*            added switch NOGETCH, getch() will be defined as getchar()   */
/*            aditional output in test()                                   */
/*            NOGETCH didn't do what it was supposed to. So I removed it.  */
/*            fixed a bug in s_rotors(). The rotor was changed, but this   */
/*               wasn't shown to the user.                                 */
/*            fixed the cls() routine for vt100. Should do it now.         */
/*            added option -c, which emulates a green cover over the lamps */
/*            inserted the USAGE and SWITCHES sections above for easier    */
/*               porting                                                   */
/*   7.1.1995 title()                                                      */
/*   8.1.1995 confirm()                                                    */
/*               - returns 0 on <Enter>                                    */
/*               - returns 1 on <Esc>                                      */
/*            test() tells                                                 */
/*               - that 80*25 text mode is assumed                         */
/*               - if curses is used                                       */
/*   9.1.1995 new switches:                                                */
/*               SUN     uses ^L for cls()                                 */
/*               NEEDSCR all non positioned output has an additional <CR>  */
/*               feeble attempts to hide the cursor.                       */
/*            mputs():                                                     */
/*               new function replacing puts(), implements NEEDSCR         */
/*            putxy():                                                     */
/*               debugging of vt100,MSDOSBW modes                          */
/*               cursor is put to 0,0 after operation                      */
/*            cls():                                                       */ 
/*               debugging of vt100,MSDOSBW modes                          */
/*            gr_exit():                                                   */
/*               cursor is set to 0,0 for leaving in VT320 mode            */
/*            title():                                                     */
/*                uses mputs()                                             */
/*            tests on the SPARCS with                                     */
/*                 xterm: works, cursor visible in upper left corner       */
/*                 cmdtool, commandline:                                   */
/*                       background white,                                 */
/*                       cursor visible  in upper left corner              */
/*  10.1.1995 tests on vt320 terminals:                                    */
/*                  slow output, especially writexy()                      */
/*                  cursor hidden                                          */
/*            test():                                                      */
/*                  uses mput()                                            */
/*            setup():                                                     */
/*                  removed surplus cls()                                  */
/*            gr_exit():                                                   */
/*                  restores now cursor                                    */
/*            cls():                                                       */
/*                  MSDOSBW works reverse when not on a PC                 */
/*                  to create the efffect metioned in the specification    */
/*                  that means on not PC's it's reverse to VT              */
/*  14.1.1994 replaced the define ANSI by ANSI_COL for compatibility with  */
/*               the pdcurses package                                      */
/*            DOSGCC isn't used any more                                   */
/*            replaced title() by intro() (trouble with pdcurses)          */
/*            s_plugboard():                                               */
/*               doesn't call cls() on every round (faster)                */
/*            ScreenSetCursor():                                           */
/*               removed redundant code                                    */
/*            gr_exit():                                                   */
/*               removed redundant code                                    */
/*            general facelifting                                          */

/*  16.1.1995 new switch SWEARWORDS, for using curses for output, too      */

/*  17.1.1995 debugging SWEARWORDS:                                        */

/*               gr_exit(): cls(MENU); curs_set(1);                        */

/*               No unpositioned output after gr_init()                    */
/*            testing SWEARWORDS:                                          */
/*               cmdtool,xterm, vt220 terminal:                            */
/*                  background colour isn't set                            */
/*                  cursor isn't hidden (now putting it at 80,25)          */
/*            gr_init(): added keypad(),                                   */ 
/*                  Cursorkeys and  F1 are interpreted by curses           */
/*  21.1.1995 made the CURSES switch compatible to BSD-curses              */
/*               this means I made keypad() exclusive to SWEARWORDS        */ 
/*  22.1.1995 removed surplus coding from cls()                            */
/*            New switch BSDCURSES:                                        */ 
/*               no use of keypad(),                                       */
/*               some commands are different                               */
/*               test :                                                    */
/*                  my version of bsd curses uses bit 7 (128) to show      */
/*                  standout mode. So strange characters appear on the     */
/*                  screen. (It's definitely a bug of the library)         */
/*            new function inkey():                                        */
/*               provides an interface to getch(), under MSDOS now the     */
/*               cursor keys should be recognized better                   */
/*            new switches:                                                */
/*               ATARI_ST       defines VT52 and special keys for Atari    */
/*               VT52           use vt52 graphics                          */
/*  26.1.1995 inkey() now forces characters to lower case                  */ 
/*  14.1.1995 just a few final changes. Now it's ready. (hopefully ...)    */
/*  27.4.1995 new option: -t (teletype mode) the last encrypted characters */
/*               are shown.Insufficient memory will cause the option to be */
/*               neglected. Output wil be presented in groups of five.     */
/*  15.5.1995 debugging the graphic interface                              */ 
/***************************************************************************/

#include <malloc.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>


#ifdef __MSDOS__
#ifndef MSDOS
#define MSDOS
#endif
#endif

#ifdef ATARI_ST
#define VT52
#endif
                                        /* for testing */
                                        /* should be commented out */
/*#define CURSES*/                          /* getch() is imported */
                                            /* from curses*/

/*#define DEBUG*/                           /* Display Information for */
                                            /* debugging */
                                                                        
/*#define MSDOSBW*/                         /* use vt100 b/w on the PC */
                                            /*inverse video on other systems*/

/*#define VT320*/                           /* use non ANSI compatible  */
                                            /* ESC sequences */

/*#undef __GNUC__*/                         /* Don't use GNU Library */
                                            /* under DOS */
                                            
/*#undef MSDOS*/                            /* plain vt100 7bit ASCII */


#ifdef BSDCURSES                            /* use curses for output, but */
                                            /* not the System V way       */

#define SWEARWORDS

#endif


#ifdef SWEARWORDS                       /* use curses for output ? */

#define CURSES

#else                                   /* curses prohibited for output */
#ifdef MSDOS                                /* MS DOS Computer */   
#ifdef MSDOSBW                                  /* but black & white */ 
    
#define VT 100                                      /* -> vt100 */

#else                                           /* colour */

#define COLOUR 1
#define ANSI_COL 1                                  /* -> use ansi.sys */


#endif
#else                                       /* No PC */
#ifndef VT52                               /* Neither PC nor Atari */

        /* ---- put in here : ----- */
        /* #ifdef <MySystem>        */
        
        /* #define COLOUR  (if it supports colours) */

        /* #else */

#define VT 100                              /* -> vt100 */

        /* ---- put in here : ----- */
        
        /* #endif */
#endif
#endif
#endif


#ifdef CURSES
#include <curses.h>
#endif



/*------------------------ defines for portability ------------------------ */




                 /* Farben */

#ifdef COLOUR           /* colour mode */                

                /* ---- put in here : ---- */
                /* if you don't like my definitions :*/
                
                /* #ifdef <MySystem> */
                
                /* #define ... */
                
                /* #else */             



#define KEY_NOR 112                     /* key normal: black on light grey  */
#define KEY_PRES 7                      /* key pressed: light grey on black */
#define BG 7                            /* background for the Enigma: brown */
#define BULB_NOR 8                      /* window normal: dark grey         */
                                        /*    on black                      */
#define BULB_LIT 15                     /* window lit: bright white on black*/
#define BULB_DIM  2                     /* Bulb shining through green       */
                                        /*    celluloid                     */
#define ROTOR 112                       /* Rotor: black on light grey       */
#define MENU 7                          /* normal writings in the menu      */
#define MENU_EM 15                      /* emphazised in menu               */
#define MENU_AL 4                       /* for errors in menu               */
#define MENU_CUR 112                    /* the character beneath the cursor */



                /* ---- put in here : ---- */
                /* if you don't like my definitions : */
    
                /* #endif */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -