/* Copyright (c) 1984 AT&T */ /* All Rights Reserved */ /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */ /* The copyright notice above does not evidence any */ /* actual or intended publication of such source code. */ /* #ident "@(#)crypt:crypt.c 1.8" */ #ident "$Header: /proj/irix6.5.7m/isms/eoe/cmd/crypt/RCS/crypt.c,v 1.6 1992/12/15 17:36:52 frank Exp $" /* * A one-rotor machine designed along the lines of Enigma * but considerably trivialized. */ #define ECHO 010 #include #include #define ROTORSZ 256 #define MASK 0377 #include #include #include #include #include #include char t1[ROTORSZ]; char t2[ROTORSZ]; char t3[ROTORSZ]; char cmd_label[] = "UX:crypt"; /* * some msg prints */ static void usage() { _sgi_nl_usage(SGINL_USAGE, cmd_label, gettxt(_SGI_DMMX_crypt_usage, "crypt [ -k ] [ key]")); } static void err_envvar(s) char *s; { _sgi_nl_error(SGINL_NOSYSERR, cmd_label, gettxt(_SGI_DMMX_envvar_err, "The '%s' environment variable is not defined"), s); } setup(pw) char *pw; { int ic, i, k, temp; unsigned random; char buf[13]; long seed; strncpy(buf, pw, 8); buf[8] = buf[0]; buf[9] = buf[1]; strncpy(buf, crypt(buf, &buf[8]), 13); 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> 8) &MASK); nchar = header.count; buf = (char *)malloc(nchar); p1 = buf; if(read(0, buf, nchar) != nchar) exit(1); while(nchar--) { *p1 = t2[(t3[(t1[(*p1+n1)&MASK]+n2)&MASK]-n2)&MASK]-n1; n1++; if(n1 == ROTORSZ) { n1 = 0; n2++; if(n2 == ROTORSZ) n2 = 0; } p1++; } nchar = header.count; if(write(1, buf, nchar) != nchar) exit(1); free(buf); } n1 = 0; n2 = 0; while((i=getchar()) >=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; } } exit(0); }