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.
12 * $FreeBSD: src/usr.bin/enigma/enigma.c,v 1.2.6.3 2001/08/01 23:51:34 obrien Exp $
13 * $DragonFly: src/usr.bin/enigma/enigma.c,v 1.6 2005/01/05 18:42:33 liamfoy Exp $
21 #define MINUSKVAR "CrYpTkEy"
32 static void shuffle(char *);
33 static void setup(const char *);
43 strncpy(salt
, pw
, sizeof(salt
));
44 memcpy(buf
, crypt(pw
, salt
), sizeof(buf
));
47 seed
= seed
*buf
[i
] + i
;
48 for(i
=0;i
<ROTORSZ
;i
++) {
52 for(i
=0;i
<ROTORSZ
;i
++) {
53 seed
= 5*seed
+ buf
[i
%13];
54 if( sizeof(long) > 4 ) {
55 /* Force seed to stay in 32-bit signed math */
56 if( seed
& 0x80000000 )
57 seed
= seed
| (-1L & ~0xFFFFFFFFL
);
63 ic
= (rnd
&MASK
)%(k
+1);
68 if(t3
[k
]!=0) continue;
70 while(t3
[ic
]!=0) ic
= (ic
+1) % k
;
74 for(i
=0;i
<ROTORSZ
;i
++)
79 main(int argc
, char **argv
)
81 int i
, n1
, n2
, nr1
, nr2
;
82 int secureflg
= 0, kflag
= 0;
85 if (argc
> 1 && argv
[1][0] == '-') {
86 if (argv
[1][1] == 's') {
90 } else if (argv
[1][1] == 'k') {
97 if ((cp
= getenv(MINUSKVAR
)) == NULL
) {
98 fprintf(stderr
, "%s not set\n", MINUSKVAR
);
102 } else if (argc
!= 2) {
103 setup(getpass("Enter key:"));
111 while((i
=getchar()) != -1) {
114 nr2
= deck
[nr1
]&MASK
;
118 i
= t2
[(t3
[(t1
[(i
+nr1
)&MASK
]+nr2
)&MASK
]-nr2
)&MASK
]-nr1
;
124 if(n2
==ROTORSZ
) n2
= 0;
137 shuffle(char *deckary
)
141 static long seed
= 123;
143 for(i
=0;i
<ROTORSZ
;i
++) {
144 seed
= 5*seed
+ buf
[i
%13];
147 ic
= (rnd
&MASK
)%(k
+1);
149 deckary
[k
] = deckary
[ic
];