📄 enigma4j.c
字号:
#else /* black & white */
#define KEY_NOR 0 /* black on white */
#define KEY_PRES 1 /* white on black */
#define BG 1 /* Hintergrundfarbe sw */
#define BULB_NOR 1 /* Leuchtfenster normal: wei"s */
/* auf schwarz */
#define BULB_LIT 0 /* Fenster leuchtet: wei"s auf */
/* schwarz */
#define BULB_DIM 1 /* look above */
#define ROTOR 0 /* Rotor: Schwarz auf hellgrau */
#define MENU 1 /* Normale Schrift im Men"u */
#define MENU_EM 0 /* hervorgehobenes im Men"u */
#define MENU_AL 0 /* Fehler im Men"u */
#define MENU_CUR 0 /* Das Zeichen unter dem Cursor */
#endif
/* special keys */
#define ESC 27
#define CntrlC 3
#define CntrlB 2
#define CntrlF 6
#define CntrlN 14
#define CntrlP 16
#ifdef SWEARWORDS
#ifndef BSDCURSES
/* System V curses */
#define F1 KEY_F(1)
#define UpArrw KEY_UP
#define DwnArrw KEY_DOWN
#define RghtArrw KEY_RIGHT
#define LftArrw KEY_LEFT
#else
/* BSD curses */
#define F1 315
#define UpArrw 328
#define DwnArrw 336
#define RghtArrw 333
#define LftArrw 331
#endif
#else
#ifdef ATARI_ST /* Atari ST */
#define F1 187
#define UpArrw 200
#define DwnArrw 208
#define RghtArrw 205
#define LftArrw 203
#else /* default */
#define F1 315
#define UpArrw 328
#define DwnArrw 336
#define RghtArrw 333
#define LftArrw 331
#endif
#endif
/* special characters */
/* MS-DOS */
#ifdef MSDOS
#define ULC 201 /* upper left corner */
#define URC 187 /* upper right corner */
#define LLC 200 /* lower left corner */
#define LRC 188 /* lower right corner */
#define VER 186 /* vertical bar */
#define HOR 205 /* horizontal bar */
#define TRI 30 /* marker of current rotor */
#else
/* 7 Bit ASCII */
#define ULC ' ' /* upper left corner */
#define URC ' ' /* upper right corner */
#define LLC ' ' /* lower left corner */
#define LRC ' ' /* lower right corner */
#define VER ' ' /* vertical bar */
#define HOR ' ' /* horizontal bar */
#define TRI '^' /* marker of current rotor */
#endif
/* ------------------------ other defines -------------------------------- */
/* System constants */
#define ROWS 25
#define COLUMNS 80
#define KEY_XOFFS 4 /* x-offset of the keys */
#define TRACEXOFS 6 /* x-offset of the tracing */
/* information (shows the */
/* steps of encryption) */
/* wirings of the rotors */
#define ROT_t "abcdefghijklmnopqrstuvwxyz" /* rotor for testing */
#define ROT_i "ekmflgdqvzntowyhxuspaibrcj" /* rotor 1 */
#define ROT_ii "ajdksiruxblhwtmcqgznpyfvoe" /* rotor 2 */
#define ROT_iii "bdfhjlcprtxvznyeiwgakmusqo" /* rotor 3 */
#define ROT_iv "esovpzjayquirhxlnftgkdcmwb" /* rotor 4 */
#define ROT_v "vzbrgityupsdnhlxawmjqofeck"
/* in which position will this rotor*/
/* will this rotor be turned */
/* together with its left neighbour*/
#define NOTCH_t 'z'
#define NOTCH_i 'q'
#define NOTCH_ii 'e'
#define NOTCH_iii 'v'
#define NOTCH_iv 'j'
#define NOTCH_v 'z'
/* reflectors */
#define REFL_t "abcdefghijklmnopqrstuvwxyz" /* reflector f. test. */
#define REFL_b "yruhqsldpxngokmiebfzcwvjat" /* reflector B, thick */
#define REFL_c "fvpjiaoyedrzxwgctkuqsbnmhl" /* reflector C, thick */
/* ------------------------- global constants ---------------------------- */
int rotor[4]; /* actual rotor position (elektr.) */
int window[4]; /* ----------"-----------(visuell) */
int rot_ini[4]; /* first -----"------- */
char *rot_wir[4]; /* wiring of the rotors */
int rot_notch[4]; /* switching positions */
int rot_typ[4]; /* which rotor (t,1-5) */
char *refl; /* wiring of the reflector */
int refl_typ; /* which reflektor ?*/
char *stecker; /* wirings of the plugboard */
int stepwidth; /* 0:test 1:normal */
char *ttystrip; /* a string containing the encoded */
/* message */
int fivecount; /* used for grouping tty output*/
/* options */
int debug; /* shall the steps of encryption*/
/* be displayed? */
int cell_cover; /* green celluloid cover */
/* over the bulbs */
int teletype; /* shall the last encrypted */
/* characters be shown ? */
/* ------------------- Deklarations --------------------------------------- */
#ifdef __STDC__ /* ANSI declarations */
int modulo(int n, int mod);
#else /* K&R declarations */
int modulo();
#endif
/* ---------------------------- Graphik Interface --------------------- */
/*............................. Basic Functions ....................... */
int inkey() /* return a single integer */
/* if a key is pressed */
{
int ret;
ret=getch();
#ifdef MSDOS /* On a MSDOS System getch() */
/* might return twice on special*/
/* keys. The first value is */
/* zero, the second one is the */
/* scancode.Some implementations*/
/* of getch() return the */
/* scancode plus 256 on special */
/* characters. This behavior is */
/* enforced by the following. */
if(!ret)
ret=256+getch();
#endif
if((ret <= 255) && isupper(ret))
ret=tolower(ret);
return(ret);
}
mputs(s) /* as a replacement for puts() */
char *s;
{
#ifdef NEEDSCR
printf("%s\r\n",s);
#else
puts(s);
#endif
}
char *translate(x) /* 2 digit number to string */
/* returns newly allocated string */
int x;
{
char s[3];
int m,n;
s[2]='\0';
m=0;
n=x;
while(n>=10){
n-=10;
m++;
}
s[0]='0'+m;
m=0;
while(n>0){
n--;
m++;
}
s[1]='0'+m;
if(s[0]=='0'){
s[0]=s[1];
s[1]=s[2];
}
return(strdup(s));
}
void gr_init() /* initialise graphics */
{
#ifdef CURSES /* CURSES library */
initscr(); /* initialisation */
cbreak(); /* imidiate input */
noecho(); /* don't echo input */
#endif
#ifdef SWEARWORDS
#ifndef BSDCURSES /* Not supported by */
/* BSD curses : */
keypad(stdscr,TRUE); /* let curses interpret */
/* special keys */
curs_set(0); /* cusor invisible */
refresh();
#endif
#endif
#ifdef VT52 /* vt52 */
printf("\033E"); /* cls */
printf("\033f");
#endif
#ifdef VT320 /* incompatible to ANSI.SYS */
printf("\033[?25l"); /* invisible Cursor */
#endif
}
void ScreenSetCursor(x,y) /* move Cursor to position (x,y) */
/* --- DUMMY --- */
int x,y;
{
}
void ScreenPutChar(ch,attr,x,y) /* put a character on a certain */
/* position in a certain colour */
int ch; /* character */
int attr; /* colour */
int x,y; /* position */
{
char *pos1,*pos2;
#ifndef MSDOS /* No MS-DOS? */
if(ch>127) /* -> Only 7Bit ASCII */
return;
#endif
#ifdef COLOUR /* Colour */
#ifdef ANSI_COL /* ANSI.SYS */
/* move cursor */
pos1=translate(x+1);
pos2=translate(y+1);
printf("\033[%s;%sH",pos2,pos1);
free(pos1);
free(pos2);
/* set colour */
printf("\033[0;8;");
switch(attr){
case 2:
printf("32;");
printf("40");
break;
case 4:
printf("31;");
printf("40");
break;
case 7:
printf("40;");
printf("37");
break;
case 8:
printf("1;30;40");
break;
case 14:
printf("40;");
printf("33;1");
break;
case 15:
printf("37;1;");
printf("40");
break;
case 96:
printf("30;");
printf("41");
break;
case 112:
printf("30;");
printf("47");
break;
}
putchar('m');
/* character */
putchar(ch);
/* move away cursor */
printf("\033[25;80H");
fflush(stdout);
#else /* other colour routines */
/*---- put your colour routine here ---*/
#endif
#else /* black & white */
#ifdef VT /* vt100 */
/* move cursor */
pos1=translate(x+1);
pos2=translate(y+1);
printf("\033[%s;%sH",pos2,pos1);
free(pos1);
free(pos2);
/* invert if necessary */
printf("\033[0;");
if(attr){
}else{
printf("7");
}
putchar('m');
putchar(ch); /* character */
/* move away cursor */
printf("\033[0;79H");
fflush(stdout);
#else
#ifdef SWEARWORDS /* curses */
#ifdef BSDCURSES /* do it BSD */
if(!attr) /* revert if necessary */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -