16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 /*
32 * A one-rotor machine designed along the lines of Enigma
33 * but considerably trivialized.
34 */
35
36 /* EXPORT DELETE START */
37 #define ECHO 010
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <string.h>
42 #include <crypt.h>
43 #include <errno.h>
44
45 #define ROTORSZ 256
46 #define MASK 0377
47 char t1[ROTORSZ];
48 char t2[ROTORSZ];
49 char t3[ROTORSZ];
50
51 static void
52 setup(pw)
53 char *pw;
54 {
55 int ic, i, k, temp;
56 unsigned random;
79 t3[i] = 0;
80 }
81 for (i = 0; i < ROTORSZ; i++) {
82 seed = 5*seed + buf[i%13];
83 random = seed % 65521;
84 k = ROTORSZ-1 - i;
85 ic = (random&MASK)%(k+1);
86 random >>= 8;
87 temp = t1[k];
88 t1[k] = t1[ic];
89 t1[ic] = temp;
90 if (t3[k] != 0) continue;
91 ic = (random&MASK) % k;
92 while (t3[ic] != 0) ic = (ic+1) % k;
93 t3[k] = ic;
94 t3[ic] = k;
95 }
96 for (i = 0; i < ROTORSZ; i++)
97 t2[t1[i]&MASK] = i;
98 }
99 /* EXPORT DELETE END */
100
101 int
102 main(int argc, char **argv)
103 {
104 /* EXPORT DELETE START */
105 extern int optind;
106 char *p1;
107 int i, n1, n2, nchar;
108 int c;
109 struct {
110 long offset;
111 unsigned int count;
112 } header;
113 int pflag = 0;
114 int kflag = 0;
115 char *buf;
116 char key[8];
117 char keyvar[] = "CrYpTkEy=XXXXXXXX";
118 char *s;
119
120 if (argc < 2) {
121 if ((buf = (char *)getpass("Enter key:")) == NULL) {
122 (void) fprintf(stderr, "Cannot open /dev/tty\n");
123 exit(1);
124 }
182 nchar = header.count;
183 if (write(1, buf, nchar) != nchar)
184 exit(1);
185 free(buf);
186 }
187
188 n1 = 0;
189 n2 = 0;
190
191 while ((i = getchar()) >= 0) {
192 i = t2[(t3[(t1[(i+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1;
193 (void) putchar(i);
194 n1++;
195 if (n1 == ROTORSZ) {
196 n1 = 0;
197 n2++;
198 if (n2 == ROTORSZ) n2 = 0;
199 }
200 }
201 return (0);
202 /* EXPORT DELETE END */
203 }
|
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 /*
32 * A one-rotor machine designed along the lines of Enigma
33 * but considerably trivialized.
34 */
35
36 #define ECHO 010
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <crypt.h>
42 #include <errno.h>
43
44 #define ROTORSZ 256
45 #define MASK 0377
46 char t1[ROTORSZ];
47 char t2[ROTORSZ];
48 char t3[ROTORSZ];
49
50 static void
51 setup(pw)
52 char *pw;
53 {
54 int ic, i, k, temp;
55 unsigned random;
78 t3[i] = 0;
79 }
80 for (i = 0; i < ROTORSZ; i++) {
81 seed = 5*seed + buf[i%13];
82 random = seed % 65521;
83 k = ROTORSZ-1 - i;
84 ic = (random&MASK)%(k+1);
85 random >>= 8;
86 temp = t1[k];
87 t1[k] = t1[ic];
88 t1[ic] = temp;
89 if (t3[k] != 0) continue;
90 ic = (random&MASK) % k;
91 while (t3[ic] != 0) ic = (ic+1) % k;
92 t3[k] = ic;
93 t3[ic] = k;
94 }
95 for (i = 0; i < ROTORSZ; i++)
96 t2[t1[i]&MASK] = i;
97 }
98
99 int
100 main(int argc, char **argv)
101 {
102 extern int optind;
103 char *p1;
104 int i, n1, n2, nchar;
105 int c;
106 struct {
107 long offset;
108 unsigned int count;
109 } header;
110 int pflag = 0;
111 int kflag = 0;
112 char *buf;
113 char key[8];
114 char keyvar[] = "CrYpTkEy=XXXXXXXX";
115 char *s;
116
117 if (argc < 2) {
118 if ((buf = (char *)getpass("Enter key:")) == NULL) {
119 (void) fprintf(stderr, "Cannot open /dev/tty\n");
120 exit(1);
121 }
179 nchar = header.count;
180 if (write(1, buf, nchar) != nchar)
181 exit(1);
182 free(buf);
183 }
184
185 n1 = 0;
186 n2 = 0;
187
188 while ((i = getchar()) >= 0) {
189 i = t2[(t3[(t1[(i+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1;
190 (void) putchar(i);
191 n1++;
192 if (n1 == ROTORSZ) {
193 n1 = 0;
194 n2++;
195 if (n2 == ROTORSZ) n2 = 0;
196 }
197 }
198 return (0);
199 }
|