diff options
author | joerg <joerg@FreeBSD.org> | 1998-10-30 18:24:54 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1998-10-30 18:24:54 +0000 |
commit | 52a3cc418d15a021df568b6f6d3c5d03c251db6e (patch) | |
tree | cf70a7da616d7688bb240bc4d51b9029d6813bd2 /usr.bin/enigma/enigma.c | |
parent | 0185a58913534ea4af562b31502977ed0361d977 (diff) | |
download | FreeBSD-src-52a3cc418d15a021df568b6f6d3c5d03c251db6e.zip FreeBSD-src-52a3cc418d15a021df568b6f6d3c5d03c251db6e.tar.gz |
Fix some of the more blatant bugs in the original code, provide a
BSD-able Makefile, add a man page (that also puts a bold warning about
the weakness of the encryption), and implement the -k option for
compatibility with other vendor's implementations. (Unlike those
other vendors, we actually also document this option and its
problems.)
There are more violations of style(9) in it, like the not-use of
getopt(3), but it's not worth the while fixing all of this.
Diffstat (limited to 'usr.bin/enigma/enigma.c')
-rw-r--r-- | usr.bin/enigma/enigma.c | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/usr.bin/enigma/enigma.c b/usr.bin/enigma/enigma.c index 3808cc7..3b1560c 100644 --- a/usr.bin/enigma/enigma.c +++ b/usr.bin/enigma/enigma.c @@ -10,23 +10,30 @@ * Upgraded to function properly on 64-bit machines. */ -#define ECHO 010 +#include <sys/types.h> +#include <sys/wait.h> + #include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define MINUSKVAR "CrYpTkEy" + +#define ECHO 010 #define ROTORSZ 256 #define MASK 0377 char t1[ROTORSZ]; char t2[ROTORSZ]; char t3[ROTORSZ]; char deck[ROTORSZ]; -char *getpass(); char buf[13]; -void shuffle(); -void puth(); +void shuffle(char *); void setup(pw) -char *pw; + char *pw; { int ic, i, k, temp, pf[2], pid; unsigned random; @@ -97,18 +104,32 @@ char *pw; t2[t1[i]&MASK] = i; } +int main(argc, argv) -char *argv[]; + char *argv[]; { register int i, n1, n2, nr1, nr2; - int secureflg = 0; + int secureflg = 0, kflag = 0; + char *cp; - if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 's') { - argc--; - argv++; - secureflg = 1; + if (argc > 1 && argv[1][0] == '-') { + if (argv[1][1] == 's') { + argc--; + argv++; + secureflg = 1; + } else if (argv[1][1] == 'k') { + argc--; + argv++; + kflag = 1; + } } - if (argc != 2){ + if (kflag) { + if ((cp = getenv(MINUSKVAR)) == NULL) { + fprintf(stderr, "%s not set\n", MINUSKVAR); + exit(1); + } + setup(cp); + } else if (argc != 2) { setup(getpass("Enter key:")); } else @@ -117,7 +138,7 @@ char *argv[]; n2 = 0; nr2 = 0; - while((i=getchar()) >=0) { + while((i=getchar()) != -1) { if (secureflg) { nr1 = deck[n1]&MASK; nr2 = deck[nr1]&MASK; @@ -138,6 +159,8 @@ char *argv[]; } } } + + return 0; } void @@ -158,16 +181,3 @@ shuffle(deck) deck[ic] = temp; } } - -void -puth( title, cp, len ) -char *title; -char *cp; -int len; -{ - fprintf( stderr, "%s = ", title); - while( len-- > 0 ) { - fprintf(stderr, "%2.2x ", (*cp++) & 0xFF ); - } - fprintf(stderr,"\n"); -} |