From 8b056529bc7dfe12f6e11c055c835659c6a1ddff Mon Sep 17 00:00:00 2001 From: Tom London Date: Thu, 18 Jan 1979 23:50:44 -0500 Subject: [PATCH] Bell 32V development Work on file usr/src/cmd/crypt.c Co-Authored-By: John Reiser Synthesized-from: 32v --- usr/src/cmd/crypt.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 usr/src/cmd/crypt.c diff --git a/usr/src/cmd/crypt.c b/usr/src/cmd/crypt.c new file mode 100644 index 0000000000..b53e451d0f --- /dev/null +++ b/usr/src/cmd/crypt.c @@ -0,0 +1,91 @@ +/* + * A one-rotor machine designed along the lines of Enigma + * but considerably trivialized. + */ + +#define ECHO 010 +#include +#define ROTORSZ 256 +#define MASK 0377 +char t1[ROTORSZ]; +char t2[ROTORSZ]; +char t3[ROTORSZ]; +char *getpass(); + +setup(pw) +char *pw; +{ + int ic, i, k, temp, pf[2]; + unsigned random; + char buf[13]; + long seed; + + strncpy(buf, pw, 8); + while (*pw) + *pw++ = '\0'; + buf[8] = buf[0]; + buf[9] = buf[1]; + pipe(pf); + if (fork()==0) { + close(0); + close(1); + dup(pf[0]); + dup(pf[1]); + execl("/usr/lib/makekey", "-", 0); + execl("/lib/makekey", "-", 0); + exit(1); + } + write(pf[1], buf, 10); + wait((int *)NULL); + if (read(pf[0], buf, 13) != 13) { + fprintf(stderr, "crypt: cannot generate key\n"); + exit(1); + } + seed = 123; + for (i=0; i<13; i++) + seed = seed*buf[i] + i; + for(i=0;i>= 8; + temp = t1[k]; + t1[k] = t1[ic]; + t1[ic] = temp; + if(t3[k]!=0) continue; + ic = (random&MASK) % k; + while(t3[ic]!=0) ic = (ic+1) % k; + t3[k] = ic; + t3[ic] = k; + } + for(i=0;i=0) { + i = t2[(t3[(t1[(i+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1; + putchar(i); + n1++; + if(n1==ROTORSZ) { + n1 = 0; + n2++; + if(n2==ROTORSZ) n2 = 0; + } + } +} -- 2.20.1