2 * "enigma.c" is in file cbw.tar from
3 * anonymous FTP host watmsg.waterloo.edu: pub/crypt/cbw.tar.Z
5 * A one-rotor machine designed along the lines of Enigma
6 * but considerably trivialized.
8 * A public-domain replacement for the UNIX "crypt" command.
10 * Upgraded to function properly on 64-bit machines.
13 #include <sys/cdefs.h>
14 __FBSDID("$FreeBSD$");
16 #include <sys/types.h>
23 #define MINUSKVAR "CrYpTkEy"
28 static char t1[ROTORSZ];
29 static char t2[ROTORSZ];
30 static char t3[ROTORSZ];
31 static char deck[ROTORSZ];
34 static void shuffle(char *);
35 static void setup(char *);
46 strlcpy(salt, pw, sizeof(salt));
47 cryptpw = crypt(pw, salt);
48 if (cryptpw == NULL) {
49 fprintf(stderr, "crypt(3) failure\n");
52 memcpy(buf, cryptpw, sizeof(buf));
55 seed = seed*buf[i] + i;
56 for(i=0;i<ROTORSZ;i++) {
60 for(i=0;i<ROTORSZ;i++) {
61 seed = 5*seed + buf[i%13];
64 ic = (rnd&MASK)%(k+1);
69 if(t3[k]!=0) continue;
71 while(t3[ic]!=0) ic = (ic+1) % k;
75 for(i=0;i<ROTORSZ;i++)
80 main(int argc, char *argv[])
82 int i, n1, n2, nr1, nr2;
83 int secureflg = 0, kflag = 0;
86 if (argc > 1 && argv[1][0] == '-') {
87 if (argv[1][1] == 's') {
91 } else if (argv[1][1] == 'k') {
98 if ((cp = getenv(MINUSKVAR)) == NULL) {
99 fprintf(stderr, "%s not set\n", MINUSKVAR);
103 } else if (argc != 2) {
104 setup(getpass("Enter key:"));
112 while((i=getchar()) != -1) {
115 nr2 = deck[nr1]&MASK;
119 i = t2[(t3[(t1[(i+nr1)&MASK]+nr2)&MASK]-nr2)&MASK]-nr1;
125 if(n2==ROTORSZ) n2 = 0;
138 shuffle(char deckary[])
142 static int32_t seed = 123;
144 for(i=0;i<ROTORSZ;i++) {
145 seed = 5*seed + buf[i%13];
148 ic = (rnd&MASK)%(k+1);
150 deckary[k] = deckary[ic];