[comp.sys.misc] Encryption code

johnboyd@LOGDIS1.OC.AFLC.AF.MIL (John Boyd;CRENP) (01/15/91)

Does anyone know where I might be able to get hold of either basic or c
program code for an encryption program, possibly *like* DES.  The reason I
need source is that I may have to port it to a commodore and/or atari along
with running it on a pc.  Thanx.  Please mail to me at the following
address instead of the header:

                       72341.1707@compuserve.com

mark@mips.COM (Mark G. Johnson) (01/19/91)

In article <9101160705.AA26097@logdis1.oc.aflc.af.mil> johnboyd@LOGDIS1.OC.AFLC.AF.MIL (John Boyd;CRENP) writes:

  >Does anyone know where I might be able to get hold of either basic or c
  >program code for an encryption program, possibly *like* DES.  The reason I
  >need source is that I may have to port it to a commodore and/or atari along
  >with running it on a pc.  Thanx.



Here are three different codes that perform encryption: "mix", "des", and
"xorcrypt".  They all appeared on sci.crypt within the last 18 months
or so.  Hopefully one or more of them will suit your needs.


#--------------------------Cut Here--------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before the "#! /bin/sh" line,
# then unpack it by saving it in a file and typing "sh file."
#
# Wrapped by Mark G. Johnson,,,,hal,open (mark) at hal on Fri Jan 18 10:01:02 1991
#
# unpacks with default permissions
#
# Contents : Makefile.des des.1 des.3 des.c des.test
#
if `test ! -s Makefile.des`
then
echo "x - Makefile.des"
cat > Makefile.des << '@\Rogue\Monster\'
# 
.SUFFIXES: .prt  .vw .1 .3
SRCS = des.c fdes.h sp.h fdes.c getopt.c 

UNDER_RCS = $(SRCS) des.test des.1 Makefile

all:	des 

neat:
	rm -f *.o *BAK .emacs* 

clobber: neat
	rm -f des
ci:
	ci -f -u $(UNDER_RCS)

firstci: rcsdir ci
	rcs -q -U $(UNDER_RCS)
	chmod u+w $(UNDER_RCS)
rcsdir:
	mkdir RCS

des: des.o getopt.o libdes.a 
	cc -o des  des.o getopt.o -L. -ldes
	strip des

libdes.a: fdes.c sp.h fdes.h
	cc -c -O fdes.o fdes.c -DBIG_ENDIAN
	ar rc libdes.a fdes.o

des.o: des.c
	cc -c -O  des.o des.c

getopt.o: getopt.c
	cc -c -O  getopt.o getopt.c

des.1.prt:
	tbl des.1 | psroff -man -h 

des.1.vw:
	tbl des.1 | psroff -man -t | psview -F1.0

des.3.prt:
	tbl des.3 | psroff -man -h 

des.3.vw:
	tbl des.3 | psroff -man -t | psview -F1.0

@\Rogue\Monster\
else
  echo "shar: Will not over write Makefile.des"
fi
if `test ! -s des.1`
then
echo "x - des.1"
cat > des.1 << '@\Rogue\Monster\'
.ds ]T 4 Dec 90
.ds CP \s-2\(co\f3 Copyright 1990 by David G. Koontz\f1\s+2
.de}F
.ev1
.}E
.if\n()s 'sp |\n(.pu-1v-1p
.if\n()t 'sp |\n(.pu-3v
.ifn 'sp |\n(.pu-4v
.ifn .tl Page %\*(]T
.if\n()s .tl - % -
.if\n()t \{.if o .tl Page %\*(CP\*(]T
.ife .tl \*(]T\*(CPPage % \}
'bp
.ev
..
.de}C
..
.po 1.0i
.nrIN 0.5i
.nr)S 12
.TH \f3DES 1 "" "\s+1\f6/dev/ktz\f1\s-1"
.SH \f3NAME
des \- encrypt/decrypt using fast implementation of NBS DES
.SH \f3SYNOPSIS
.B des
-e \|\(bv \|-d [-n] [-k key \|\(bv \|-K hex_key] [-p pad_character], or
.br
.B des
-t [-v]
.SH \f3DESCRIPTION
.I Des\^
encrypts or decrypts according to the
.B -e 
(encrypt) and 
.B -d 
(decrypt) flags reading from standard input and writing to standard output.
The
.B -n 
flag disables the initial and inverse initial permutations, which yields
a substantial throughput gain.
The
.B -k
flag passes a string of 8 characters to be used as key.  The
.B -K
flag passes a 16 character hexidecimal key.  The DES algorithm
produces a 64 bit cipher product using a 56 bit key and 64 bit plaintext value.
.PP
If no key is passed 
.I des\^
uses the routine getpass("key: ") to 
demand an 8 character key from standard input.  All key inputs must be of
the correct length or
.I des\^ 
will  terminate.
.PP
Character string keys (
.B -k 
and
.B getpass()
) have each byte shifted left one bit, to leave bit[0] undefined.  Bit[0] is
used as a parity bit, and is otherwise uninvolved in DES keys.  Shifting
character string keys provides retention of all ascii defined bits and
results in a 56 bit key.  Hex key strings, such as from the 
.B -K
option or from the test vector, are not shifted.  It is the hex key provider's
responsibility to properly position 7 bits of key into the upper 7 bits of each
hex byte.
.PP
The 
.B -p
flag passes a hexidecimal value of the range 0x0 - 0xFF to be used in place
of the default pad character (0x20).
The pad character is used to fill out the last 8 byte block if the input
stream does not supply muliples of 8 bytes.
.SH \f3TESTMODE
The 
.B -t
and 
.B -v
flags are used to toggle 
.I test\^
and 
.I verbose\^
modes.  Testmode switches input format to test vectors used in DES algorithm
verification.  Each vector includes a 16 hexdigit key, a 16 hexdigit data 
value and a 16 hexdigit result value.  All output during testmode operation is 
made to standard error output.  A summary of tests is output irregardless of
the 
.I -v\^ 
flag.  Verbose mode outputs the test source and error locations.
.PP
Initial permutation, and inverse initial permutation are always executed during
test mode.
.SH \f3TEST VECTOR FORMAT
 An input line must contain less than 127 characters.  A line containing
a leading space is considered a vector.  A line without a leading
space is a comment.  The 
.I des\^
mode is set for vectors following a comment line that contains either
.B encrypt
or
.B decrypt
as the first 7 characters.
A line containing a vector is comprised
of a leading space and three 16 hexdigit values.
.PP
A trailing comment line in the vector file forces output of the error
total.
.SH \f3NORMAL OPERATION
.I Des\^
encrypts and decrypts with the same key:
.PP
.RS
des -e -k key < clear >cypher
.br
des -d -k key < cypher 
.RE
.PP
will output a stream identical to that contained in clear, with the exeception
of the possibility of up to 7 pad characters being appended to the decoded
stream. 
.PP
Files encrypted by
.I des\^
are compatible with the National Bureau of Standards Digital Encryption
Standard in an electronic code book (ECB) implementation with regard to
the 
.B -n
flag.
.PP
.I des\^
utilizes a faster implementation of the DES algorithm.
Performance increases derive from merging the  P permutation into the S Boxes
and structural optimization to reduce operations on bits to the minimum.
.PP
.I des\^
can provide interoperable secure data between different systems and 
implementations of DES (including chips) when using key input in hex strings.
.I Des\^ 
also has the capabilty of decrypting concatenated files, if
all used the same key schedule and key.
.SH \f3EXAMPLE
.IP
des -e -k abcdefgh < foo.c > fum
.PP
will use the string "abcdefgh" as key
to encrypt the contents of "foo.c", and place the encrypted
output in file "fum".  File "fum" at this point will be unreadable.
.SM \f3NOTE:\f1 
that the original file, "foo.c", remains in readable form.
To obtain readable print-out of the file "fum", it
could be decoded as follows:
.IP
des -d < fum
.PP
After the response:
.IP
key:
.PP
the user types in "abcdefgh".
.SH \f3IMPLEMENTATION
The des implementation has two subroutines 
.B des()
and
.B no_ip_des().
The routine des() calls the routine no_ip_des() after first performing
the initial permutation.  Upon return the inverse permutation is performed.
Both routines return void, and accept identical arguments, a pointer to
a block of data, and a mode flag indicating key schedule shift direction.
The basic data structure is a union between two unsigned longs (32 bit)
and a character array length 9.  (the extra byte is used in a crypt() 
implementation.)  As the interfaces to des() and no_ip_des() are identical,
no_ip_des() can be called directly, saving the processing time for bit
operations, and pushing performance.
.PP
The program destime has been included (SYSV times() calls) for measuring
performance.  On an IRIS 4D-25/G, 20 MHz MIPS R3000, FPU, cache, plenty
of RAM, and SCSI disk I/O the throughput has been measured at
33+ kbytes/sec with IP/IP-1, and 55+ kbytes/sec without IP/IP-1.  The
same values are measured, either with simple iteration or disk I/O.  The
standard size file for measurement is 40 kbytes.

.SH \f3BYTE ORDERING
Because the input block is a union between a character string, and two
longs, there are can be byte misordering.  While this will prevent the
test vectors from passing properly, it does not affect cryptographic 
security of the algorithm.  There are two possible solutions, 
reordering the input data, which is painful and ridiculous, and
modifying the initial and inverse initial permutations.
.PP
The source for the algorithm has two byte endian versions
available by compiler switch.  The two most common types, 
.B BIG_ENDIAN
and 
.B LITTLE_ENDIAN
are supported.
PDP-11 an other byte orders are not currently supported, but could
be easily added.
.SH \f3FILES
.tr *
.ta \w'des.test\ \ \ \ 'u
des.test	test vector file, derived from \f2NBS Special Pub 500-20\f1
.br
.sp
endian		Program for determining byte in long order.
.br
.sp
sbox		Program for generating sbox with P permutation
.br
*		in proper byte order.  E permutation is hand done.
.br
.sp
destime		Program for measuring execution time of the des algorithm.
.br
.tr
.DT
.SH \f3SEE ALSO
crypt(1),
makekey(1),
des(3)
.SH \f3BUGS
Encryption of large files is time consuming.
.I des\^
uses a new implementation
of the DES algorithm requiring the host machine have 32 bit longs.
des uses unions between an array of two longs and an array of nine characters.
Because of these unions, Des may be compiled for either Big-endian or 
Little-endian character string to long byte ordering.  Use of the new DES
implementation provides substantial throughput improvement over using the
DES implementation in libcrypt.
.PP
.I des\^
uses padding of the input to assemble the last block of data.  This can
result in up to 7 characters added to the decoded data.  If having the pad
character selectable is not flexible enough, a pipeline filter can be written
to protect and stuff a pad value in the plaintext domain, and strip pad
characters from the decoded output.
.br
@\Rogue\Monster\
else
  echo "shar: Will not over write des.1"
fi
if `test ! -s des.3`
then
echo "x - des.3"
cat > des.3 << '@\Rogue\Monster\'
.ds ]T 4 Dec 90
.ds CP \s-2\(co\f3 Copyright 1990 by David G. Koontz\f1\s+2
.de}F
.ev1
.}E
.if\n()s 'sp |\n(.pu-1v-1p
.if\n()t 'sp |\n(.pu-3v
.ifn 'sp |\n(.pu-4v
.ifn .tl Page %\*(]T
.if\n()s .tl - % -
.if\n()t \{.if o .tl Page %\*(CP\*(]T
.ife .tl \*(]T\*(CPPage % \}
'bp
.ev
..
.de}C
..
.po 1.0i
.nrIN 0.5i
.nr)S 12
.TH \f3DES 3 "" "\s+1\f6/dev/ktz\f1\s-1"
.SH \f3NAME
des, no_ip_des, loadkey, \- fast NBS DES encryption routines
.SH \f3SYNOPSIS
.B void des (block,desmode)
.br
.sp
.B void no_ip_des (block,desmode)
.br
.B union LR_block *block;
.br
.B int desmode;
.br
.sp
.B union LR_block {
.br
.B unsigned long LR[2];
.br
.B unsigned char string[8];
.br
.B };
.br
.sp
.B void loadkey (key,shift)
.br
.B char *key;
.br
.B int shift;
.br
.sp
.SH \f3DESCRIPTION
.B des\^ 
is a fast implementation of the NBS Digital Encryption Algorithm (DEA), found
in FIPS PUB 46, Data Encryption Standard (DES).
While software implementations of DES are not certified, compliance 
can be verified by the use of the program des in test mode with test data 
derived from FIPS Special Publication 5000-20.
.PP
Data input is via the long aligned 8 byte string
.I block\^.
The
.I desmode\^ 
flag determines encryption (
.B 0
) or decryption (
.B 1
).
.PP
.B no_ip_des
interfaces identically, and does not perform the
initial permutation (
.B IP
), and inverse initial permutation (
.B IP -1
), and is consequentially faster.
.I des\^
performs the initial permutation, calls
.I no_ip_des\^,
and on return, performs the inverse initial permutation.
.PP
.B loadkey
is used to load a 
.I key\^
comprised of 8 characters into the key scheduler for
.I des\^.
The routine loadkey must be invoked before execution of 
.I des\^
or
.I no_ip_des\^,
failure to do so results in an undefined key value, and the possibility
that data become unrecoverable.  The
.B shift
flag is used to determine whether or not each byte in the key string is
shifted left one position or not.  A 
.B 1
indicates that a shift is required.  Bit 0 is used as an optional parity
bit for 7 significant bits per byte of key.  Shifting the key up one bit,
preserves all the bits in an ascii key string.  Preformatted keys can be
used with
.I shift\^
reset to
.B 0.
.I loadkey\^
overwrites the first 8 character positions of the string key.
.SH \f3SEE ALSO
des(1), encrypt(3), setkey(3), crypt(3)
.SH \f3BUGS
.I des\^
uses a union between unsigned longs (32 bit) and a character array.
This is sensitive to host CPU byte ordering.  Portability is provided for
by the use of compiler flags.
.PP
The routine 
.B no_ip_des
makes the assumption that right shifted values in the unsigned long variable
.B pre_S
leave 
.B 0's
in undefined left bit positions when performing the E permutation for S Box 8.
This may be either compiler or CPU dependant.
Corrective action includes adding an AND mask to reset bits 4 and 5 of the 
variable pre_S to zero in the exception routine for S Box 8.
.PP
Length checking of variables accessed by passed pointers is not performed.
.br
@\Rogue\Monster\
else
  echo "shar: Will not over write des.3"
fi
if `test ! -s des.c`
then
echo "x - des.c"
cat > des.c << '@\Rogue\Monster\'
/*
 * Copyright (c) 1990 David G. Koontz.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the above mentioned individual.
 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE
 */
#ifndef lint
char copyright[]=
    "@(#) Copyright (c) 1990 David G. Koontz\n All rights reserved.\n";
#endif

/*  des -- perform encryption/decryption using DES algorithm */

#define TRUE		1
#define FALSE		0
#define SHIFT		1
#define NOSHIFT		0
extern int  optind,opterr;
extern char *optarg;

#include <sys/types.h>
#include <stdio.h>
#include <string.h>

char *getpass();
void *des(), *loadkey();

#define BYTES_PER_BLOCK	    8
#define NYBBLES_PER_BLOCK   16
#define NUMBER_OF_KEY_BYTES 8
#define BITS_PER_NYBBLE	    4
#define BIT(x)		    ( 1 << x)
#define TODEC		    16
#define ENCRYPT		    0
#define DECRYPT		    1

union LR_block {
    unsigned char string[9];
    unsigned long     LR[2];
};

main (argc,argv)
int argc;
char **argv;
{
    union LR_block data;
    unsigned char key[NUMBER_OF_KEY_BYTES];
    unsigned char testinput[128];
    unsigned char testkey[NYBBLES_PER_BLOCK+1];
    unsigned char testplain[NYBBLES_PER_BLOCK+1];
    unsigned char testcipher[NYBBLES_PER_BLOCK+1];
    unsigned char testresult[NYBBLES_PER_BLOCK+1];
    int len,c;
    int verbose = FALSE;
    int testerrors = 0;
    int totalerrors = 0;
    int testcount = 0;
    int needkey = TRUE;
    int desmode = ENCRYPT;
    int no_ip_iip = FALSE;
    int testmode = FALSE;
    char padchar = 0x20;	/* default pad character is space */

    if (argc < 2)
	goto usage;

    while (( c = getopt(argc,argv,"ednk:K:p:tv")) != EOF) {
	switch (c){
	    case 'e':
		desmode = ENCRYPT;
		break;
	    case 'd':
		desmode = DECRYPT;
		break;
	    case 'n':
		no_ip_iip = TRUE;
	    break;
	    case 'k':
		if (needkey) {
		    needkey = FALSE;
		    if ( (c = optarg[0]) == '-')  /* prevent lost data */
			goto usage;
		    if ( (c = strlen(optarg)) < 8) {
			fprintf(stderr,"%s: key must be 8 char\n",argv[0]);
			exit(1);
		    }
		    loadkey(optarg,SHIFT);
		}
		else {
		    fprintf(stderr,"%s: too many keys\n",argv[0]);
		    exit(1);
		}
		break;
	    case 'K':
		if ( needkey ) {
		    needkey = FALSE;
		    strxtoc(optarg,key);  /* will complain about bad format */
		    while (*optarg) *optarg++ = 0;
		    loadkey(key,NOSHIFT);
		}
		else {
		    fprintf(stderr,"%s: too many keys\n",argv[0]);
		    exit(1);
		}
		break;
	    case 'p':
		padchar = (unsigned char) strtol(optarg,0,TODEC);
		break;
	    case 't':
		testmode = TRUE;
		break;
	    case 'v':
		verbose = TRUE;
		break;
	    case '?':
usage:		fprintf(stderr,"Usage: %s -e | -d ",argv[0]);
		fprintf(stderr,"[-k key | -K hex_key] ");
		fprintf(stderr,"[-p hex_pad_char]\n\n");
		fprintf(stderr,"   Or: %s -t [-v]\n\n",argv[0]);
		exit(1);
		break;
	}
    }

    if ( testmode && no_ip_iip)
	no_ip_iip = FALSE;
    if (needkey && !testmode ) {
	strncpy(key,getpass("key: "),8);
	if ( (c = strlen(key)) < 8)  {
	    fprintf(stderr,"%s: key must be 8 char\n",argv[0]);
	    exit(1);
        }
	loadkey(key,SHIFT);
    }

    if ( no_ip_iip) 		    /* fastest  mode */
	while ((len = fread(data.string, 1, BYTES_PER_BLOCK, stdin)) > 0) {

	    if ( len < BYTES_PER_BLOCK ) {	/* encrypt mode only */
		while (len < BYTES_PER_BLOCK)	/* last block */
		data.string[len++]=padchar;
	    } 
	    no_ip_des(&data,desmode);
	    fwrite(data.string, 1, BYTES_PER_BLOCK, stdout);
	}
     else if ( !testmode)	    /* regular operation loop */
	while ((len = fread(data.string, 1, BYTES_PER_BLOCK, stdin)) > 0) {

	    if ( len < BYTES_PER_BLOCK ) {
		while (len < BYTES_PER_BLOCK)
		data.string[len++]=padchar;
	    }
	    des(&data,desmode);
	    fwrite(data.string, 1, BYTES_PER_BLOCK, stdout);
	}

    else    /* test mode */

    {
 	while (fgets(testinput,(sizeof testinput) -1, stdin) != NULL ) {

	    if ( strncmp(testinput,"encrypt",7) == 0) { /* mode = encode */
	        desmode = ENCRYPT;
	        fprintf(stderr,"%s",testinput);
	    }
	    else
	    if ( strncmp(testinput,"decrypt",7) == 0) { /* mode = decode */
	        fprintf(stderr,"%s",testinput);
	        desmode = DECRYPT;
	    }
	    else 
	    if ( strncmp(testinput," ",1) == 0) { /* key, plain & cipher */
		testcount++;
	        len = sscanf(testinput,"%s%s%s*",
	    	    testkey, testplain, testcipher);
		if ( verbose )  {
		    fprintf(stderr," %s %s %s\n", testkey, testplain,
							   testcipher);
		}
		strxtoc(testkey,key);
		loadkey(key,NOSHIFT);
		strxtoc(testplain,data.string);
		des(&data,desmode);
		strctox(data.string,testresult);
		if ( (len = strncasecmp(testcipher,testresult,16)) != 0 ) {
		    fprintf(stderr,"Test: %d -- ERROR expected %s got %s\n",
			    testcount,testcipher,testresult);
		    testerrors++;
		}
	    }
	    else {				  /* nothing but eyewash */
		if ( testcount ) {
		    fprintf(stderr," %d tests performed\n",testcount);
		    fprintf(stderr," ERRORS on these tests : %d\n",testerrors);
		    totalerrors +=testerrors;
		    testcount = 0;
		    testerrors = 0;
		}
		fprintf(stderr,"%s",testinput);
	    }
	}
    fprintf(stderr,"Total Errors = %d\n",totalerrors);
    }
return(0);
}

strxtoc(hexstr,charstr)  /* converts 16 hex digit strings to char strings */
char *hexstr,*charstr;
{
#define UPPER_NYBBLE	( !(val & 1) )

    unsigned char c;
    int val;
    for (val = 0; val < NYBBLES_PER_BLOCK;val++) {
	if ((hexstr[val] >= '0') && (hexstr[val] <= '9'))
	    if (UPPER_NYBBLE)
	        c = (hexstr[val] - '0') << BITS_PER_NYBBLE;
	    else
		c += hexstr[val] - '0';
	else
	if ((hexstr[val] >= 'A') && (hexstr[val] <= 'F'))
	    if (UPPER_NYBBLE)
	        c = (hexstr[val] - 'A' +10) << BITS_PER_NYBBLE;
	    else
		c += hexstr[val] - 'A' +10;
	else
	if ((hexstr[val] >= 'a') && (hexstr[val] <= 'f'))
	    if (UPPER_NYBBLE)
	        c = (hexstr[val] - 'a' +10) << BITS_PER_NYBBLE;
	    else
		c += hexstr[val] - 'a' +10;
	else {
	    fprintf(stderr,"hex conversion error: %s - char %d\n",hexstr,val);
	    if ((val = strlen(hexstr)) != NYBBLES_PER_BLOCK)
		fprintf(stderr,"hex string length != 16\n");
	    exit(1);
	}
	if ( UPPER_NYBBLE)
	    charstr[val>>1] = 0;
	else
	    charstr[val>>1] = c;
    }
}

strctox(charstr,hexstr)  /* converts 8 char string to 16 hex digit string */
char *charstr,*hexstr;
{
    unsigned char c;
    int i;
    for (i = 0; i < 8; i++) {
	c = charstr[i] >> BITS_PER_NYBBLE;  /* uppper nybble */
	if ( c <= 9)
	    *hexstr++ = c + '0';
	else
	    *hexstr++ = c + '7';
	    
	c = (charstr[i] & 0xf);
	if ( c <= 9)
	    *hexstr++ = c + '0';
	else
	    *hexstr++ = c + '7';
    }
    *hexstr = 0;
}
@\Rogue\Monster\
else
  echo "shar: Will not over write des.c"
fi
if `test ! -s des.test`
then
echo "x - des.test"
cat > des.test << '@\Rogue\Monster\'
# Test vectors for DES Electronic Code Book (ECB)
# implementation, derived from:
#   "Validating the Correctness of Hardware 
#   Implementations of the NBS Data Encryption Standard"
#   NBS Special Publication 500-20, 1980.
#
#    Initial Permutation and Expansion test
#
encrypt
#
 0101010101010101 95F8A5E5DD31D900 8000000000000000
 0101010101010101 DD7F121CA5015619 4000000000000000
 0101010101010101 2E8653104F3834EA 2000000000000000
 0101010101010101 4BD388FF6CD81D4F 1000000000000000
 0101010101010101 20B9E767B2FB1456 0800000000000000
 0101010101010101 55579380D77138EF 0400000000000000
 0101010101010101 6CC5DEFAAF04512F 0200000000000000
 0101010101010101 0D9F279BA5D87260 0100000000000000
 0101010101010101 D9031B0271BD5A0A 0080000000000000
 0101010101010101 424250B37C3DD951 0040000000000000
 0101010101010101 B8061B7ECD9A21E5 0020000000000000
 0101010101010101 F15D0F286B65BD28 0010000000000000
 0101010101010101 ADD0CC8D6E5DEBA1 0008000000000000
 0101010101010101 E6D5F82752AD63D1 0004000000000000
 0101010101010101 ECBFE3BD3F591A5E 0002000000000000
 0101010101010101 F356834379D165CD 0001000000000000
 0101010101010101 2B9F982F20037FA9 0000800000000000
 0101010101010101 889DE068A16F0BE6 0000400000000000
 0101010101010101 E19E275D846A1298 0000200000000000
 0101010101010101 329A8ED523D71AEC 0000100000000000
 0101010101010101 E7FCE22557D23C97 0000080000000000
 0101010101010101 12A9F5817FF2D65D 0000040000000000
 0101010101010101 A484C3AD38DC9C19 0000020000000000
 0101010101010101 FBE00A8A1EF8AD72 0000010000000000
 0101010101010101 750D079407521363 0000008000000000
 0101010101010101 64FEED9C724C2FAF 0000004000000000
 0101010101010101 F02B263B328E2B60 0000002000000000
 0101010101010101 9D64555A9A10B852 0000001000000000
 0101010101010101 D106FF0BED5255D7 0000000800000000
 0101010101010101 E1652C6B138C64A5 0000000400000000
 0101010101010101 E428581186EC8F46 0000000200000000
 0101010101010101 AEB5F5EDE22D1A36 0000000100000000
 0101010101010101 E943D7568AEC0C5C 0000000080000000
 0101010101010101 DF98C8276F54B04B 0000000040000000
 0101010101010101 B160E4680F6C696F 0000000020000000
 0101010101010101 FA0752B07D9C4AB8 0000000010000000
 0101010101010101 CA3A2B036DBC8502 0000000008000000
 0101010101010101 5E0905517BB59BCF 0000000004000000
 0101010101010101 814EEB3B91D90726 0000000002000000
 0101010101010101 4D49DB1532919C9F 0000000001000000
 0101010101010101 25EB5FC3F8CF0621 0000000000800000
 0101010101010101 AB6A20C0620D1C6F 0000000000400000
 0101010101010101 79E90DBC98F92CCA 0000000000200000
 0101010101010101 866ECEDD8072BB0E 0000000000100000
 0101010101010101 8B54536F2F3E64A8 0000000000080000
 0101010101010101 EA51D3975595B86B 0000000000040000
 0101010101010101 CAFFC6AC4542DE31 0000000000020000
 0101010101010101 8DD45A2DDF90796C 0000000000010000
 0101010101010101 1029D55E880EC2D0 0000000000008000
 0101010101010101 5D86CB23639DBEA9 0000000000004000
 0101010101010101 1D1CA853AE7C0C5F 0000000000002000
 0101010101010101 CE332329248F3228 0000000000001000
 0101010101010101 8405D1ABE24FB942 0000000000000800
 0101010101010101 E643D78090CA4207 0000000000000400
 0101010101010101 48221B9937748A23 0000000000000200
 0101010101010101 DD7C0BBD61FAFD54 0000000000000100
 0101010101010101 2FBC291A570DB5C4 0000000000000080
 0101010101010101 E07C30D7E4E26E12 0000000000000040
 0101010101010101 0953E2258E8E90A1 0000000000000020
 0101010101010101 5B711BC4CEEBF2EE 0000000000000010
 0101010101010101 CC083F1E6D9E85F6 0000000000000008
 0101010101010101 D2FD8867D50D2DFE 0000000000000004
 0101010101010101 06E7EA22CE92708F 0000000000000002
 0101010101010101 166B40B44ABA4BD6 0000000000000001
#
#    Inverse Permutation and Expansion test 
#
encrypt
#
 0101010101010101 8000000000000000 95F8A5E5DD31D900
 0101010101010101 4000000000000000 DD7F121CA5015619
 0101010101010101 2000000000000000 2E8653104F3834EA
 0101010101010101 1000000000000000 4BD388FF6CD81D4F
 0101010101010101 0800000000000000 20B9E767B2FB1456
 0101010101010101 0400000000000000 55579380D77138EF
 0101010101010101 0200000000000000 6CC5DEFAAF04512F
 0101010101010101 0100000000000000 0D9F279BA5D87260
 0101010101010101 0080000000000000 D9031B0271BD5A0A
 0101010101010101 0040000000000000 424250B37C3DD951
 0101010101010101 0020000000000000 B8061B7ECD9A21E5
 0101010101010101 0010000000000000 F15D0F286B65BD28
 0101010101010101 0008000000000000 ADD0CC8D6E5DEBA1
 0101010101010101 0004000000000000 E6D5F82752AD63D1
 0101010101010101 0002000000000000 ECBFE3BD3F591A5E
 0101010101010101 0001000000000000 F356834379D165CD
 0101010101010101 0000800000000000 2B9F982F20037FA9
 0101010101010101 0000400000000000 889DE068A16F0BE6
 0101010101010101 0000200000000000 E19E275D846A1298
 0101010101010101 0000100000000000 329A8ED523D71AEC
 0101010101010101 0000080000000000 E7FCE22557D23C97
 0101010101010101 0000040000000000 12A9F5817FF2D65D
 0101010101010101 0000020000000000 A484C3AD38DC9C19
 0101010101010101 0000010000000000 FBE00A8A1EF8AD72
 0101010101010101 0000008000000000 750D079407521363
 0101010101010101 0000004000000000 64FEED9C724C2FAF
 0101010101010101 0000002000000000 F02B263B328E2B60
 0101010101010101 0000001000000000 9D64555A9A10B852
 0101010101010101 0000000800000000 D106FF0BED5255D7
 0101010101010101 0000000400000000 E1652C6B138C64A5
 0101010101010101 0000000200000000 E428581186EC8F46
 0101010101010101 0000000100000000 AEB5F5EDE22D1A36
 0101010101010101 0000000080000000 E943D7568AEC0C5C
 0101010101010101 0000000040000000 DF98C8276F54B04B
 0101010101010101 0000000020000000 B160E4680F6C696F
 0101010101010101 0000000010000000 FA0752B07D9C4AB8
 0101010101010101 0000000008000000 CA3A2B036DBC8502
 0101010101010101 0000000004000000 5E0905517BB59BCF
 0101010101010101 0000000002000000 814EEB3B91D90726
 0101010101010101 0000000001000000 4D49DB1532919C9F
 0101010101010101 0000000000800000 25EB5FC3F8CF0621
 0101010101010101 0000000000400000 AB6A20C0620D1C6F
 0101010101010101 0000000000200000 79E90DBC98F92CCA
 0101010101010101 0000000000100000 866ECEDD8072BB0E
 0101010101010101 0000000000080000 8B54536F2F3E64A8
 0101010101010101 0000000000040000 EA51D3975595B86B
 0101010101010101 0000000000020000 CAFFC6AC4542DE31
 0101010101010101 0000000000010000 8DD45A2DDF90796C
 0101010101010101 0000000000008000 1029D55E880EC2D0
 0101010101010101 0000000000004000 5D86CB23639DBEA9
 0101010101010101 0000000000002000 1D1CA853AE7C0C5F
 0101010101010101 0000000000001000 CE332329248F3228
 0101010101010101 0000000000000800 8405D1ABE24FB942
 0101010101010101 0000000000000400 E643D78090CA4207
 0101010101010101 0000000000000200 48221B9937748A23
 0101010101010101 0000000000000100 DD7C0BBD61FAFD54
 0101010101010101 0000000000000080 2FBC291A570DB5C4
 0101010101010101 0000000000000040 E07C30D7E4E26E12
 0101010101010101 0000000000000020 0953E2258E8E90A1
 0101010101010101 0000000000000010 5B711BC4CEEBF2EE
 0101010101010101 0000000000000008 CC083F1E6D9E85F6
 0101010101010101 0000000000000004 D2FD8867D50D2DFE
 0101010101010101 0000000000000002 06E7EA22CE92708F
 0101010101010101 0000000000000001 166B40B44ABA4BD6
#
#   Key Permutation tests
#
encrypt
#
 8001010101010101 0000000000000000 95A8D72813DAA94D
 4001010101010101 0000000000000000 0EEC1487DD8C26D5
 2001010101010101 0000000000000000 7AD16FFB79C45926
 1001010101010101 0000000000000000 D3746294CA6A6CF3
 0801010101010101 0000000000000000 809F5F873C1FD761
 0401010101010101 0000000000000000 C02FAFFEC989D1FC
 0201010101010101 0000000000000000 4615AA1D33E72F10
 0180010101010101 0000000000000000 2055123350C00858
 0140010101010101 0000000000000000 DF3B99D6577397C8
 0120010101010101 0000000000000000 31FE17369B5288C9
 0110010101010101 0000000000000000 DFDD3CC64DAE1642
 0108010101010101 0000000000000000 178C83CE2B399D94
 0104010101010101 0000000000000000 50F636324A9B7F80
 0102010101010101 0000000000000000 A8468EE3BC18F06D
 0101800101010101 0000000000000000 A2DC9E92FD3CDE92
 0101400101010101 0000000000000000 CAC09F797D031287
 0101200101010101 0000000000000000 90BA680B22AEB525
 0101100101010101 0000000000000000 CE7A24F350E280B6
 0101080101010101 0000000000000000 882BFF0AA01A0B87
 0101040101010101 0000000000000000 25610288924511C2
 0101020101010101 0000000000000000 C71516C29C75D170
 0101018001010101 0000000000000000 5199C29A52C9F059
 0101014001010101 0000000000000000 C22F0A294A71F29F
 0101012001010101 0000000000000000 EE371483714C02EA
 0101011001010101 0000000000000000 A81FBD448F9E522F
 0101010801010101 0000000000000000 4F644C92E192DFED
 0101010401010101 0000000000000000 1AFA9A66A6DF92AE
 0101010201010101 0000000000000000 B3C1CC715CB879D8
 0101010180010101 0000000000000000 19D032E64AB0BD8B
 0101010140010101 0000000000000000 3CFAA7A7DC8720DC
 0101010120010101 0000000000000000 B7265F7F447AC6F3
 0101010110010101 0000000000000000 9DB73B3C0D163F54
 0101010108010101 0000000000000000 8181B65BABF4A975
 0101010104010101 0000000000000000 93C9B64042EAA240
 0101010102010101 0000000000000000 5570530829705592
 0101010101800101 0000000000000000 8638809E878787A0
 0101010101400101 0000000000000000 41B9A79AF79AC208
 0101010101200101 0000000000000000 7A9BE42F2009A892
 0101010101100101 0000000000000000 29038D56BA6D2745
 0101010101080101 0000000000000000 5495C6ABF1E5DF51
 0101010101040101 0000000000000000 AE13DBD561488933
 0101010101020101 0000000000000000 024D1FFA8904E389
 0101010101018001 0000000000000000 D1399712F99BF02E
 0101010101014001 0000000000000000 14C1D7C1CFFEC79E
 0101010101012001 0000000000000000 1DE5279DAE3BED6F
 0101010101011001 0000000000000000 E941A33F85501303
 0101010101010801 0000000000000000 DA99DBBC9A03F379
 0101010101010401 0000000000000000 B7FC92F91D8E92E9
 0101010101010201 0000000000000000 AE8E5CAA3CA04E85
 0101010101010180 0000000000000000 9CC62DF43B6EED74
 0101010101010140 0000000000000000 D863DBB5C59A91A0
 0101010101010120 0000000000000000 A1AB2190545B91D7
 0101010101010110 0000000000000000 0875041E64C570F7
 0101010101010108 0000000000000000 5A594528BEBEF1CC
 0101010101010104 0000000000000000 FCDB3291DE21F0C0
 0101010101010102 0000000000000000 869EFD7F9F265A09
#
#   Test of right-shifts in Decryption
#
decrypt
#
 8001010101010101 95A8D72813DAA94D 0000000000000000
 4001010101010101 0EEC1487DD8C26D5 0000000000000000
 2001010101010101 7AD16FFB79C45926 0000000000000000
 1001010101010101 D3746294CA6A6CF3 0000000000000000
 0801010101010101 809F5F873C1FD761 0000000000000000
 0401010101010101 C02FAFFEC989D1FC 0000000000000000
 0201010101010101 4615AA1D33E72F10 0000000000000000
 0180010101010101 2055123350C00858 0000000000000000
 0140010101010101 DF3B99D6577397C8 0000000000000000
 0120010101010101 31FE17369B5288C9 0000000000000000
 0110010101010101 DFDD3CC64DAE1642 0000000000000000
 0108010101010101 178C83CE2B399D94 0000000000000000
 0104010101010101 50F636324A9B7F80 0000000000000000
 0102010101010101 A8468EE3BC18F06D 0000000000000000
 0101800101010101 A2DC9E92FD3CDE92 0000000000000000
 0101400101010101 CAC09F797D031287 0000000000000000
 0101200101010101 90BA680B22AEB525 0000000000000000
 0101100101010101 CE7A24F350E280B6 0000000000000000
 0101080101010101 882BFF0AA01A0B87 0000000000000000
 0101040101010101 25610288924511C2 0000000000000000
 0101020101010101 C71516C29C75D170 0000000000000000
 0101018001010101 5199C29A52C9F059 0000000000000000
 0101014001010101 C22F0A294A71F29F 0000000000000000
 0101012001010101 EE371483714C02EA 0000000000000000
 0101011001010101 A81FBD448F9E522F 0000000000000000
 0101010801010101 4F644C92E192DFED 0000000000000000
 0101010401010101 1AFA9A66A6DF92AE 0000000000000000
 0101010201010101 B3C1CC715CB879D8 0000000000000000
 0101010180010101 19D032E64AB0BD8B 0000000000000000
 0101010140010101 3CFAA7A7DC8720DC 0000000000000000
 0101010120010101 B7265F7F447AC6F3 0000000000000000
 0101010110010101 9DB73B3C0D163F54 0000000000000000
 0101010108010101 8181B65BABF4A975 0000000000000000
 0101010104010101 93C9B64042EAA240 0000000000000000
 0101010102010101 5570530829705592 0000000000000000
 0101010101800101 8638809E878787A0 0000000000000000
 0101010101400101 41B9A79AF79AC208 0000000000000000
 0101010101200101 7A9BE42F2009A892 0000000000000000
 0101010101100101 29038D56BA6D2745 0000000000000000
 0101010101080101 5495C6ABF1E5DF51 0000000000000000
 0101010101040101 AE13DBD561488933 0000000000000000
 0101010101020101 024D1FFA8904E389 0000000000000000
 0101010101018001 D1399712F99BF02E 0000000000000000
 0101010101014001 14C1D7C1CFFEC79E 0000000000000000
 0101010101012001 1DE5279DAE3BED6F 0000000000000000
 0101010101011001 E941A33F85501303 0000000000000000
 0101010101010801 DA99DBBC9A03F379 0000000000000000
 0101010101010401 B7FC92F91D8E92E9 0000000000000000
 0101010101010201 AE8E5CAA3CA04E85 0000000000000000
 0101010101010180 9CC62DF43B6EED74 0000000000000000
 0101010101010140 D863DBB5C59A91A0 0000000000000000
 0101010101010120 A1AB2190545B91D7 0000000000000000
 0101010101010110 0875041E64C570F7 0000000000000000
 0101010101010108 5A594528BEBEF1CC 0000000000000000
 0101010101010104 FCDB3291DE21F0C0 0000000000000000
 0101010101010102 869EFD7F9F265A09 0000000000000000
#
#   Data permutation test
#
encrypt
#
 1046913489980131 0000000000000000 88D55E54F54C97B4
 1007103489988020 0000000000000000 0C0CC00C83EA48FD
 10071034C8980120 0000000000000000 83BC8EF3A6570183
 1046103489988020 0000000000000000 DF725DCAD94EA2E9
 1086911519190101 0000000000000000 E652B53B550BE8B0
 1086911519580101 0000000000000000 AF527120C485CBB0
 5107B01519580101 0000000000000000 0F04CE393DB926D5
 1007B01519190101 0000000000000000 C9F00FFC74079067
 3107915498080101 0000000000000000 7CFD82A593252B4E
 3107919498080101 0000000000000000 CB49A2F9E91363E3
 10079115B9080140 0000000000000000 00B588BE70D23F56
 3107911598080140 0000000000000000 406A9A6AB43399AE
 1007D01589980101 0000000000000000 6CB773611DCA9ADA
 9107911589980101 0000000000000000 67FD21C17DBB5D70
 9107D01589190101 0000000000000000 9592CB4110430787
 1007D01598980120 0000000000000000 A6B7FF68A318DDD3
 1007940498190101 0000000000000000 4D102196C914CA16
 0107910491190401 0000000000000000 2DFA9F4573594965
 0107910491190101 0000000000000000 B46604816C0E0774
 0107940491190401 0000000000000000 6E7E6221A4F34E87
 19079210981A0101 0000000000000000 AA85E74643233199
 1007911998190801 0000000000000000 2E5A19DB4D1962D6
 10079119981A0801 0000000000000000 23A866A809D30894
 1007921098190101 0000000000000000 D812D961F017D320
 100791159819010B 0000000000000000 055605816E58608F
 1004801598190101 0000000000000000 ABD88E8B1B7716F1
 1004801598190102 0000000000000000 537AC95BE69DA1E1
 1004801598190108 0000000000000000 AED0F6AE3C25CDD8
 1002911498100104 0000000000000000 B3E35A5EE53E7B8D
 1002911598190104 0000000000000000 61C79C71921A2EF8
 1002911598100201 0000000000000000 E2F5728F0995013C
 1002911698100101 0000000000000000 1AEAC39A61F0A464
#
#   S-Box test
#
encrypt
#
 7CA110454A1A6E57 01A1D6D039776742 690F5B0D9A26939B
 0131D9619DC1376E 5CD54CA83DEF57DA 7A389D10354BD271
 07A1133E4A0B2686 0248D43806F67172 868EBB51CAB4599A
 3849674C2602319E 51454B582DDF440A 7178876E01F19B2A
 04B915BA43FEB5B6 42FD443059577FA2 AF37FB421F8C4095
 0113B970FD34F2CE 059B5E0851CF143A 86A560F10EC6D85B
 0170F175468FB5E6 0756D8E0774761D2 0CD3DA020021DC09
 43297FAD38E373FE 762514B829BF486A EA676B2CB7DB2B7A
 07A7137045DA2A16 3BDD119049372802 DFD64A815CAF1A0F
 04689104C2FD3B2F 26955F6835AF609A 5C513C9C4886C088
 37D06BB516CB7546 164D5E404F275232 0A2AEEAE3FF4AB77
 1F08260D1AC2465E 6B056E18759F5CCA EF1BF03E5DFA575A
 584023641ABA6176 004BD6EF09176062 88BF0DB6D70DEE56
 025816164629B007 480D39006EE762F2 A1F9915541020B56
 49793EBC79B3258F 437540C8698F3CFA 6FBF1CAFCFFD0556
 4FB05E1515AB73A7 072D43A077075292 2F22E49BAB7CA1AC
 49E95D6D4CA229BF 02FE55778117F12A 5A6B612CC26CCE4A
 018310DC409B26D6 1D9D5C5018F728C2 5F4C038ED12B2E41
 1C587F1C13924FEF 305532286D6F295A 63FAC0D034D9F793
# Errors found:
@\Rogue\Monster\
else
  echo "shar: Will not over write des.test"
fi
echo "Finished archive 1 of 2"
#
#
#
# This is a shell archive.  Remove anything before the "#! /bin/sh" line,
# then unpack it by saving it in a file and typing "sh file."
#
# Wrapped by Mark G. Johnson,,,,hal,open (mark) at hal on Fri Jan 18 10:01:02 1991
#
# unpacks with default permissions
#
# Contents : fdes.c fdes.h getopt.c mix.c mix.man sp.h
#	xorcrypt.Description xorcrypt.c
#
if `test ! -s fdes.c`
then
echo "x - fdes.c"
cat > fdes.c << '@\Rogue\Monster\'
/*
 * Copyright (c) 1990 David G. Koontz.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms.  Inclusion in a product or release
 * as part of a package for sale is not agreed to.  Storing this
 * software in a nonvolatile storage device characterized  as an 
 * integrated circuit providing read only memory (ROM), either as
 * source code or machine executeable instructions is similarly not
 * agreed to.  THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
 * IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE
 */
#ifndef lint
char Copyright[]=
    "@(#) Copyright (c) 1990 David G. Koontz\n All rights reserved.\n";
#endif
/*
 *	fdes.c - faster implementation of DES algorithm.
 */

#include "fdes.h"
void
loadkey(key,shift)
    char *key;
    int shift;
{
    register int i,Key,sbox,bit, C_carry,D_carry;
    register unsigned long C = 0;
    register unsigned long D = 0;

    if (shift)			     /* ascii keys -  save bit 0 */
	for (i=0;i < KEY_BYTES;i++)
	    key[i] = key[i] << 1;

    for (i=0;i< CD_BITS;i++) {		/* load C and D registers  */
	if( key[PC1_C[i] >> 4] & BIT((PC1_C[i] & 0xf)))
	    C |= BIT(i);
	if( key[PC1_D[i] >> 4] & BIT((PC1_D[i] & 0xf)))
	    D |= BIT(i);
    }

	for(i=0;i< KEY_BYTES;i++)	  /* erase key source */
	    key[i] = 0;

    for ( Key = 0; Key < KEY_SCHEDULE; Key++) {
	for ( i = 0; i < leftshift[Key];i++) {
	    C_carry = C & 1;
	    D_carry = D & 1;
	    C = C >> 1;		/* rotate C and D */
	    D = D >> 1;
	    if (C_carry)
		C |= BIT(27);
	    if (D_carry)
		D |= BIT(27);
	}
	for (sbox = 0; sbox < 8; sbox++){  /* load Key S Box Key_Scheds */
	    K_S[sbox][Key]=0;

	    for (bit = 0; bit < 6; bit++){

		if ( sbox < 4) {
		    if ( C & BIT(PC2_S18[sbox][bit]) )
			K_S[sbox][Key] |= BIT(bit);
		}
		else {
		    if ( D & BIT(PC2_S18[sbox][bit]) )
			K_S[sbox][Key] |= BIT(bit);
		}
	    }
	}
    }
}

void
no_ip_des(block,desmode)
    union LR_block *block;
    int desmode;
{
    register int round,pre_S,sbox;
    register unsigned long E_S,temp_f;
    register unsigned long Bit31,Bit0;

    for (round = 0; round < KEY_SCHEDULE; round++) {	/* f(R,K) */

	temp_f = 0;
	Bit31 = (block->LR[RR] & BIT(31))?(BIT(4)):0;
	E_S   = block->LR[RR] << 1;
	E_S  |= (Bit31)?1:0;	 /* S1 - R31,R0,R1,R2,R3,R4,...R30 */
	Bit0  = (block->LR[RR] & 1)?(BIT(5)):0;	    /* save for S8 */

	for (sbox = 0; sbox < 8; sbox++) {
	    pre_S = E_S & 0x3F;			/* lower 6 bits  */

	    if (sbox == 7) {	/* S8, pre_S bits 4,5 expected to be 0 */
		pre_S |= Bit0;			
		pre_S |= Bit31;	/* S8 - R27,R28,R29,R30,R31,R0,0,...0 */
	    }
	    else
		E_S >>= 4;	/* S2 - R3,R4,R5,R6,R7,R8,...R30,0,...0 */

	    if ( !desmode )			/* encrypt mode */
		pre_S ^= K_S[sbox][round];
	    else				/* decrypt mode */
		pre_S ^= K_S[sbox][(KEY_SCHEDULE-1)-round];

	    temp_f |= sbox_P[sbox][pre_S];    /* sbox in P output   */
	}				
	temp_f ^= block->LR[LL];	/* f(R,K) EXOR L  */
	block->LR[LL] = block->LR[RR];	/* move R to L */
	block->LR[RR] = temp_f;		/* new R       */
    }

    block->LR[RR] = block->LR[LL];    /* output block is R16L16 */
    block->LR[LL] = temp_f;
}

void
des(block,desmode)
    union LR_block *block;
    int desmode;
{
    int byte,bit;
    static union LR_block ip_iip;

    ip_iip.LR[LL]=0; ip_iip.LR[RR]=0;

    for (byte = 0; byte < 8; byte++) {		    /* IP */
	for (bit = 0; bit < 8; bit++) {
	if ( block->string[byte] & BIT(bit)) 
	    if ( bit & 1)			    /* odd bits to R */
		ip_iip.LR[RR] |= IP[byte][bit];
	    else
		ip_iip.LR[LL] |= IP[byte][bit];	    /* even bits to L */
	}
    }
    no_ip_des(&ip_iip,desmode);

    block->LR[AA] = 0; block->LR[BB] = 0;

    for (byte = 0; byte < 8; byte++) {		    /* Inverse IP */
	for (bit = 0; bit < 8; bit++) {
	    if (ip_iip.string[byte] & BIT(bit))
		if (bit < 4)
		    block->LR[BB] |= IIP[byte][bit];
		else
		    block->LR[AA] |= IIP[byte][bit];
	}
    }
}
@\Rogue\Monster\
else
  echo "shar: Will not over write fdes.c"
fi
if `test ! -s fdes.h`
then
echo "x - fdes.h"
cat > fdes.h << '@\Rogue\Monster\'
/*
 * Copyright (c) 1990 David G. Koontz.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the above mentioned individual.
 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE
 */
/*
 *	fdes.h  - faster implementation of DES algorithm
 */

#ifndef BIG_ENDIAN
#define LITTLE_ENDIAN
#endif
#define BIT(x)	( 1 << x )

#define KEY_BYTES		8
#define CD_BITS			28
#define KEY_SCHEDULE		16
#define AA 0
#define BB 1
#define RR 1
#define LL 0

union LR_block {
	unsigned char string[9];
	unsigned long LR[2];
};

/* Key Schedule permuted for S Box input: */

static unsigned long K_S[8][16];	/*  K_S[sbox][Key] */

/* PC1_C/D are ByteBit indexes into an key input as a string of 8 chars */

static int PC1_C[28] = {
	        0x77, 0x67, 0x57, 0x47, 0x37, 0x27, 0x17, 0x07,
		0x76, 0x66, 0x56, 0x46, 0x36, 0x26, 0x16, 0x06,
		0x75, 0x65, 0x55, 0x45, 0x35, 0x25, 0x15, 0x05,
		0x74, 0x64, 0x54, 0x44
		};
static int PC1_D[28] = {
		0x71, 0x61, 0x51, 0x41, 0x31, 0x21, 0x11, 0x01,
		0x72, 0x62, 0x52, 0x42, 0x32, 0x22, 0x12, 0x02,
		0x73, 0x63, 0x53, 0x43, 0x33, 0x23, 0x13, 0x03,
		                        0x34, 0x24, 0x14, 0x04 
		};

/* Key Schedule shifts*/
static int leftshift[] = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1 };

/* PC2 has been converted to C and D lookups, 6 bits input to 8 s boxes
 * Column and row straightened out LSB to MSB.  Bit 0 - 5 order.
 */
/* S1 thru S4 from C, S5 thru S8 from D */
 static int PC2_S18[8][6] = {
	   13,  16,  10,  23,   0,   4,	    /* S1 */
	    2,  27,  14,   5,  20,   9,	    /* S2 */
	   22,  18,  11,   3,  25,   7,	    /* S3 */
	   15,   6,  26,  19,  12,   1,	    /* S4 */
	   12,  23,   2,   8,  18,  26,	    /* S5 */
	    1,  11,  22,  16,   4,  19,     /* S6 */
	   15,  20,  10,  27,   5,  24,	    /* S7 */
	   17,  13,  21,   7,   0,   3	    /* S8 */
};

#ifdef BIG_ENDIAN

static unsigned long  IP[8][8] = {
1 << 31, 1 << 31, 1 << 23, 1 << 23, 1 << 15, 1 << 15, 1 << 7, 1 << 7,
1 << 30, 1 << 30, 1 << 22, 1 << 22, 1 << 14, 1 << 14, 1 << 6, 1 << 6,
1 << 29, 1 << 29, 1 << 21, 1 << 21, 1 << 13, 1 << 13, 1 << 5, 1 << 5,
1 << 28, 1 << 28, 1 << 20, 1 << 20, 1 << 12, 1 << 12, 1 << 4, 1 << 4,
1 << 27, 1 << 27, 1 << 19, 1 << 19, 1 << 11, 1 << 11, 1 << 3, 1 << 3,
1 << 26, 1 << 26, 1 << 18, 1 << 18, 1 << 10, 1 << 10, 1 << 2, 1 << 2,
1 << 25, 1 << 25, 1 << 17, 1 << 17, 1 <<  9, 1 <<  9, 1 << 1, 1 << 1,
1 << 24, 1 << 24, 1 << 16, 1 << 16, 1 <<  8, 1 <<  8, 1 << 0, 1 << 0
};
static unsigned long IIP[8][8] = {
1 <<  0, 1 <<  8, 1 << 16, 1 << 24, 1 <<  0, 1 <<  8, 1 << 16, 1 << 24, 
1 <<  2, 1 << 10, 1 << 18, 1 << 26, 1 <<  2, 1 << 10, 1 << 18, 1 << 26,
1 <<  4, 1 << 12, 1 << 20, 1 << 28, 1 <<  4, 1 << 12, 1 << 20, 1 << 28,
1 <<  6, 1 << 14, 1 << 22, 1 << 30, 1 <<  6, 1 << 14, 1 << 22, 1 << 30,
1 <<  1, 1 <<  9, 1 << 17, 1 << 25, 1 <<  1, 1 <<  9, 1 << 17, 1 << 25,
1 <<  3, 1 << 11, 1 << 19, 1 << 27, 1 <<  3, 1 << 11, 1 << 19, 1 << 27,
1 <<  5, 1 << 13, 1 << 21, 1 << 29, 1 <<  5, 1 << 13, 1 << 21, 1 << 29,
1 <<  7, 1 << 15, 1 << 23, 1 << 31, 1 <<  7, 1 << 15, 1 << 23, 1 << 31
};

#else /* LITTLE_ENDIAN */

static unsigned long  IP[8][8] = {
1 << 7, 1 << 7, 1 << 15, 1 << 15, 1 << 23, 1 << 23, 1 << 31, 1 << 31,
1 << 6, 1 << 6, 1 << 14, 1 << 14, 1 << 22, 1 << 22, 1 << 30, 1 << 30,
1 << 5, 1 << 5, 1 << 13, 1 << 13, 1 << 21, 1 << 21, 1 << 29, 1 << 29,
1 << 4, 1 << 4, 1 << 12, 1 << 12, 1 << 20, 1 << 20, 1 << 28, 1 << 28,
1 << 3, 1 << 3, 1 << 11, 1 << 11, 1 << 19, 1 << 19, 1 << 27, 1 << 27,
1 << 2, 1 << 2, 1 << 10, 1 << 10, 1 << 18, 1 << 18, 1 << 26, 1 << 26,
1 << 1, 1 << 1, 1 <<  9, 1 <<  9, 1 << 17, 1 << 17, 1 << 25, 1 << 25,
1 << 0, 1 << 0, 1 <<  8, 1 <<  8, 1 << 16, 1 << 16, 1 << 24, 1 << 24
};
static unsigned long IIP[8][8] = {
1 << 24, 1 << 16, 1 <<  8, 1 <<  0, 1 << 24, 1 << 16, 1 <<  8, 1 <<  0,
1 << 26, 1 << 18, 1 << 10, 1 <<  2, 1 << 26, 1 << 18, 1 << 10, 1 <<  2,
1 << 28, 1 << 20, 1 << 12, 1 <<  4, 1 << 28, 1 << 20, 1 << 12, 1 <<  4,
1 << 30, 1 << 22, 1 << 14, 1 <<  6, 1 << 30, 1 << 22, 1 << 14, 1 <<  6, 
1 << 25, 1 << 17, 1 <<  9, 1 <<  1, 1 << 25, 1 << 17, 1 <<  9, 1 <<  1,
1 << 27, 1 << 19, 1 << 11, 1 <<  3, 1 << 27, 1 << 19, 1 << 11, 1 <<  3,
1 << 29, 1 << 21, 1 << 13, 1 <<  5, 1 << 29, 1 << 21, 1 << 13, 1 <<  5,
1 << 31, 1 << 23, 1 << 15, 1 <<  7, 1 << 31, 1 << 23, 1 << 15, 1 <<  7
};
#endif
#include "sp.h"
@\Rogue\Monster\
else
  echo "shar: Will not over write fdes.h"
fi
if `test ! -s getopt.c`
then
echo "x - getopt.c"
cat > getopt.c << '@\Rogue\Monster\'
#define NULL	0
#define EOF	(-1)
#define ERR(s, c)	if(opterr){	extern int strlen(), write();	char errbuf[2];	errbuf[0] = c; errbuf[1] = '\n';	(void) write(2, argv[0], (unsigned)strlen(argv[0]));	(void) write(2, s, (unsigned)strlen(s));	(void) write(2, errbuf, 2);}

extern int strcmp();
/* bsd based system will require index */
#define strchr index
extern char *strchr();

int	opterr = 1;
int	optind = 1;
int	optopt;
char	*optarg;

int
getopt(argc, argv, opts)
int	argc;
char	**argv, *opts;
{
	static int sp = 1;
	register int c;
	register char *cp;

	if(sp == 1)
		if(optind >= argc ||
		   argv[optind][0] != '-' || argv[optind][1] == '\0')
			return(EOF);
		else if(strcmp(argv[optind], "--") == NULL) {
			optind++;
			return(EOF);
		}
	optopt = c = argv[optind][sp];
	if(c == ':' || (cp=strchr(opts, c)) == NULL) {
		ERR(": illegal option -- ", c);
		if(argv[optind][++sp] == '\0') {
			optind++;
			sp = 1;
		}
		return('?');
	}
	if(*++cp == ':') {
		if(argv[optind][sp+1] != '\0')
			optarg = &argv[optind++][sp+1];
		else if(++optind >= argc) {
			ERR(": option requires an argument -- ", c);
			sp = 1;
			return('?');
		} else
			optarg = argv[optind++];
		sp = 1;
	} else {
		if(argv[optind][++sp] == '\0') {
			sp = 1;
			optind++;
		}
		optarg = NULL;
	}
	return(c);
}
@\Rogue\Monster\
else
  echo "shar: Will not over write getopt.c"
fi
if `test ! -s mix.c`
then
echo "x - mix.c"
cat > mix.c << '@\Rogue\Monster\'
/* mix.c */
/**********************************************************************
*    File Name     : mix.c
*    Object        : mix - also link to unmix, edmix, catmix, keymix
*    Berkeley cc   : cc -s -O % -o $BIN/mix
*    System V cc   : cc -s -O -DREALUNIX % -o $BIN/mix
*    Author        : Istvan Mohos, March 1987
*    Rev A Apr 14  : Do not mix last byte of file
*    Rev B Apr 27  : by Ira Chayut; R & D Associates;
*                       3625 Perkins Lane, SW; Tacoma, WA 98499
*                       (206) 581-1322 ....uw-beaver!tikal!slovax!ira
*                       add type_open in readfile()
***********************************************************************/


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>

#ifdef REALUNIX
#include <termio.h>

struct termio tbuf, tbufsave;
echo_off()
{
    ioctl (0, TCGETA, &tbuf);
    tbufsave = tbuf;
    tbuf.c_lflag &= ~ECHO;
    ioctl (0, TCSETAF, &tbuf);
}

echo_ret()
{
    ioctl (0, TCSETAF, &tbufsave);
}

#else
#include <sys/ioctl.h>

struct sgttyb tbuf, tbufsave;
echo_off()
{
    ioctl (0, TIOCGETP, &tbuf);
    tbufsave = tbuf;
    tbuf.sg_flags &= ~ECHO;
    ioctl (0, TIOCSETP, &tbuf);
}

echo_ret()
{
    ioctl (0, TIOCSETP, &tbufsave);
}

#endif

#define SMALLIM 256    /* minimum file size */
#define KMAX 128       /* maximum key size */

#define NONE    -1     /* data buffer references */
#define PLAIN    0
#define CIPHER   1
#define SMALLBUF 2
#define SCREEN   1

#define MIX    334     /* argv[0] hash values */
#define EDMIX  535
#define UNMIX  561
#define CATMIX 646
#define KEYMIX 663

struct keychar {       /* links to form chain of key bytes */
    int val;
    struct keychar *next;
};

int fstat();
struct stat sbuf;

int fd = -1, lockfd;          /* subject file, lock file */
char *plain, *cipher;         /* malloc pointers */
char *head, *tail;            /* main buffer limits */
char *gets(), *getenv();
struct keychar key[KMAX];     /* links */
int klen, flen;               /* key length, file length */
int loop;                     /* negative offset: size of main buffer */

int eflag = 0;                /* edmix command flag */
int unphase;                  /* unmix phase of edmix command */
char *estring = "vi";         /* edmix default command */
static char cmd[SMALLIM];     /* edmix system command buffer */

int argindx = 1;              /* pointer to current file */
char *fstring;                /* current file name */
static char mstring[KMAX];    /* minimum security key buffer */
char *kstring;                /* pointer to user key string */
char smallbuf[SMALLIM];       /* file buffer for files less than SMALLIM */
char lockstr[SMALLIM];        /* lock file: /tmp/mixlock$inode */
int locked = 0;               /* lock flag */
int context = 0;              /* argv[0] hash value */
int cleanup();                /* remove lock file, exit */

extern char **environ;
extern int errno;

main(argc,argv)
int argc;
char *argv[];
{

    register char *here;
    int regi;
    int donttry;              /* if unphase of edmix fails */
    int argneed = 2;
    char kbuf[SMALLIM];       /* interactive key acquisition buffers */
    char verify[SMALLIM];

    if (signal(SIGHUP, SIG_IGN) == SIG_DFL)
        signal(SIGHUP, cleanup);
    if (signal(SIGINT, SIG_IGN) == SIG_DFL)
        signal(SIGINT, cleanup);
    if (signal(SIGQUIT, SIG_IGN) == SIG_DFL)
        signal(SIGQUIT, cleanup);
    if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
        signal(SIGTERM, cleanup);

    here = argv[0] + strlen(argv[0]);
    while(--here > argv[0]) {
        if (*here == '/') {
           ++here;
           break;
        }
    }
    if (*here == '/')  /* first byte of argv[0] */
       ++here;

    while(*here)
        context += *here++;

    switch (context) {
        case KEYMIX:
        fillm();
        fprintf(stderr, "%s\n", mstring), cleanup(0);

        case EDMIX:
            if (argc > argindx) {
                for (regi = 1; regi < 5;) {
                    if (strcmp(argv[regi], "-k") == 0) {
                        argneed += 2;
                        argindx += 2;
                        if (++regi < argc)
                            kstring = argv[regi];
                    }
                    else if (strcmp(argv[regi], "-e") == 0) {
                        eflag = 1;
                        argneed += 2;
                        argindx += 2;
                        if (++regi < argc)
                            estring = argv[regi];
                    }
                    if (++regi >= argc)
                        break;
                }
            }
            break;

        default:
            if (argc > argindx) {
                for (regi = 1; regi < 3;) {
                    if (strcmp(argv[regi], "-k") == 0) {
                        argneed += 2;
                        argindx += 2;
                        if (++regi < argc)
                            kstring = argv[regi];
                    }
                    if (++regi >= argc)
                        break;
                }
            }
            break;
    }

    if (argneed > argc) {
        switch (context) {
            default:
                fprintf(stderr, "Usage: %s [ -k key ] file ...\n",
                    argv[0]), cleanup(0);

            case EDMIX:
                fprintf(stderr,
                    "Usage: %s [ -k key ] [ -e editor ] file ...\n",
                    argv[0]), cleanup(0);
        }
    }

    if (kstring == NULL) {
        kstring = getenv("MIXKEY");
        if (kstring != NULL)
            if (strlen(kstring) == 0)
                kstring = NULL;
            /* to prevent a NULL environment variable automatically
               triggering the euid conversion */
    }

    if (kstring == NULL) {
        kstring = kbuf;
        fprintf(stderr, "Key: "), fflush(stderr);
        echo_off();
        gets(kstring);
        fprintf(stderr, "\n");
        fprintf(stderr, "Again: "), fflush(stderr);
        gets(verify);
        fprintf(stderr, "\n");
        echo_ret();
        if (strcmp(kstring, verify) != 0)
            fprintf(stderr, "%c%c",7, 7), cleanup(1);
    }

    /* verify key length validity */
    if ((klen = strlen(kstring)) == 0) {
        kstring = mstring;
        fillm();
        klen = strlen(kstring);
    }
    else if (klen > KMAX)
        *(kstring + KMAX) = '\0', klen = KMAX;

    /* link up selectors into circular chain */
    for (regi = klen; --regi; key[regi].next = key + regi -1);
    key[0].next = key + klen -1;

    while (argindx < argc) {
        fstring = argv[argindx++];
        donttry = 0;

        switch (context) {
            case MIX:
                switch (readfile(PLAIN)) {
                    case 0:
                        mix();
                        writefile(CIPHER, 0);
                        break;

                    case 1:
                        break;

                    default:
                        writefile(NONE, 0);
                        break;
                }
                break;

            case UNMIX:
                switch (readfile(CIPHER)) {
                    case 0:
                        unmix();
                        writefile(PLAIN, 0);
                        break;

                    case 1:
                        break;

                    default:
                        writefile(NONE, 0);
                        break;
                }
                break;

            case EDMIX:
                unphase = 1;
                switch(readfile(CIPHER)) {
                    case 0:
                        unmix();
                        writefile(PLAIN, 0);
                        break;

                    case 1:
                        donttry = 1;
                        break;

                    default:
                        writefile(NONE, 0);
                        break;
                }

                unphase = 0;
                if (!donttry) {
                    mksys();
                    system(cmd);
    
                    switch(readfile(PLAIN)) {
                        case 0:
                            mix();
                            writefile(CIPHER, 0);
                            break;

                        default:
                            writefile(NONE, 0);
                            break;
                    }
                }
                break;

            case CATMIX:
            default:
                switch(readfile(CIPHER)) {
                    case 0:
                        unmix();
                        writefile(PLAIN, SCREEN);
                        break;

                    case 1:
                        break;

                    default:
                        writefile(SMALLBUF, SCREEN);
                        break;
                }
                break;
        }
    }
    cleanup(0);
}

/* hash buffer to manufacture minimum security key,
   filled byte-by-byte to silence the "strings" command */
static260(buf)
char *buf;
{
    register char *h = buf;

    *h++ = 106; *h++ = 97;  *h++ = 101; *h++ = 111; *h++ = 108;
    *h++ = 102; *h++ = 107; *h++ = 108; *h++ = 116; *h++ = 106;
    *h++ = 109; *h++ = 118; *h++ = 114; *h++ = 107; *h++ = 111;
    *h++ = 111; *h++ = 118; *h++ = 107; *h++ = 109; *h++ = 117;
    *h++ = 112; *h++ = 104; *h++ = 109; *h++ = 108; *h++ = 114;
    *h++ = 103; *h++ = 105; *h++ = 112; *h++ = 106; *h++ = 97;
    *h++ = 99;  *h++ = 98;  *h++ = 103; *h++ = 117; *h++ = 117;
    *h++ = 97;  *h++ = 116; *h++ = 106; *h++ = 107; *h++ = 104;
    *h++ = 110; *h++ = 122; *h++ = 121; *h++ = 100; *h++ = 119;
    *h++ = 111; *h++ = 112; *h++ = 109; *h++ = 112; *h++ = 99;
    *h++ = 97;  *h++ = 101; *h++ = 118; *h++ = 107; *h++ = 106;
    *h++ = 101; *h++ = 104; *h++ = 114; *h++ = 113; *h++ = 116;
    *h++ = 107; *h++ = 120; *h++ = 119; *h++ = 113; *h++ = 114;
    *h++ = 97;  *h++ = 119; *h++ = 121; *h++ = 110; *h++ = 122;
    *h++ = 120; *h++ = 114; *h++ = 115; *h++ = 98;  *h++ = 120;
    *h++ = 97;  *h++ = 112; *h++ = 98;  *h++ = 121; *h++ = 115;
    *h++ = 116; *h++ = 99;  *h++ = 121; *h++ = 98;  *h++ = 113;
    *h++ = 100; *h++ = 122; *h++ = 116; *h++ = 117; *h++ = 100;
    *h++ = 122; *h++ = 99;  *h++ = 114; *h++ = 101; *h++ = 100;
    *h++ = 117; *h++ = 118; *h++ = 101; *h++ = 97;  *h++ = 100;
    *h++ = 115; *h++ = 105; *h++ = 101; *h++ = 118; *h++ = 119;
    *h++ = 102; *h++ = 98;  *h++ = 101; *h++ = 116; *h++ = 106;
    *h++ = 102; *h++ = 119; *h++ = 120; *h++ = 103; *h++ = 99;
    *h++ = 102; *h++ = 118; *h++ = 107; *h++ = 103; *h++ = 120;
    *h++ = 121; *h++ = 105; *h++ = 100; *h++ = 103; *h++ = 119;
    *h++ = 108; *h++ = 106; *h++ = 121; *h++ = 122; *h++ = 106;
    *h++ = 101; *h++ = 104; *h++ = 120; *h++ = 110; *h++ = 108;
    *h++ = 122; *h++ = 97;  *h++ = 107; *h++ = 102; *h++ = 105;
    *h++ = 122; *h++ = 113; *h++ = 109; *h++ = 98;  *h++ = 98;
    *h++ = 108; *h++ = 103; *h++ = 107; *h++ = 97;  *h++ = 99;
    *h++ = 112; *h++ = 99;  *h++ = 101; *h++ = 109; *h++ = 104;
    *h++ = 108; *h++ = 98;  *h++ = 102; *h++ = 115; *h++ = 100;
    *h++ = 103; *h++ = 110; *h++ = 105; *h++ = 109; *h++ = 99;
    *h++ = 104; *h++ = 116; *h++ = 102; *h++ = 105; *h++ = 111;
    *h++ = 108; *h++ = 110; *h++ = 100; *h++ = 106; *h++ = 117;
    *h++ = 103; *h++ = 108; *h++ = 112; *h++ = 109; *h++ = 111;
    *h++ = 102; *h++ = 109; *h++ = 120; *h++ = 104; *h++ = 110;
    *h++ = 113; *h++ = 110; *h++ = 112; *h++ = 104; *h++ = 111;
    *h++ = 121; *h++ = 105; *h++ = 112; *h++ = 115; *h++ = 111;
    *h++ = 113; *h++ = 105; *h++ = 113; *h++ = 122; *h++ = 106;
    *h++ = 114; *h++ = 116; *h++ = 113; *h++ = 114; *h++ = 107;
    *h++ = 115; *h++ = 119; *h++ = 114; *h++ = 97;  *h++ = 120;
    *h++ = 115; *h++ = 115; *h++ = 108; *h++ = 118; *h++ = 121;
    *h++ = 116; *h++ = 98;  *h++ = 122; *h++ = 117; *h++ = 117;
    *h++ = 109; *h++ = 119; *h++ = 98;  *h++ = 118; *h++ = 99;
    *h++ = 99;  *h++ = 119; *h++ = 110; *h++ = 110; *h++ = 120;
    *h++ = 100; *h++ = 121; *h++ = 102; *h++ = 101; *h++ = 121;
    *h++ = 102; *h++ = 122; *h++ = 113; *h++ = 115; *h++ = 100;
    *h++ = 111; *h++ = 116; *h++ = 103; *h++ = 103; *h++ = 104;
    *h++ = 104; *h++ = 105; *h++ = 105; *h++ = 117; *h++ = 110;
    *h++ = 111; *h++ = 113; *h++ = 112; *h++ = 114; *h++ = 118;
    *h++ = 115; *h++ = 117; *h++ = 118; *h++ = 119; *h++ = 120;
    *h = 0; }

/* manufacture minimum security key */
fillm()
{
    register char *here;
    int regi;
    int ck, mlen;
    static char fbuf[12], mbuf[36];
    char bstring[261];
    char *from, *to;

    ck = geteuid();
    ++ck; /* don't want root dividing by 0 */
    strcpy(fbuf, "%c");
    strcat(fbuf, "%o");
    strcat(fbuf, " %");
    strcat(fbuf, "x ");
    strcat(fbuf, "%d"); /* just so "strings" couldn't find it */
    sprintf(mbuf, fbuf, (ck & 95) + ' ' , ck, ~ck & 0xfff,
        (~ck & 0xffff) / ck);
    static260(bstring);
    head = bstring;
    here = head + strlen(bstring);
    tail = here -1;
    loop = head - tail -1;
    from = mbuf;
    to = mstring;
    mlen = strlen(mbuf);
    for (regi = mlen; --regi >=0; ) {
        if ((here += *from++) > tail)
            here += loop;
        *to++ = *here;
    }
}

/* manufacture system command of edmix */
mksys()
{
    char *here;
    char *esp;
    int fnamlen, did_sub = 0;

    if (!eflag) {
        strcpy(cmd, estring);
        strcat(cmd, " ");
        strcat(cmd, fstring);
    }
    else {
        here = cmd;
        esp = estring;
        fnamlen = strlen(fstring);
        while (*esp) {
            if (*esp == '$') {
                strcpy(here, fstring);
                here += fnamlen;
                esp++;
                did_sub = 1;
            }
            else
               *here++ = *esp++;
        }
        if (!did_sub) {
            *here++ = ' ';
            strcpy(here, fstring);
            here += fnamlen;
        }
        *here = 0;
    }
}

cleanup(exitval)
int exitval;
{
    signal(SIGINT, SIG_IGN);
    signal(SIGHUP, SIG_IGN);
    signal(SIGQUIT, SIG_IGN);
    signal(SIGTERM, SIG_IGN);
    if (locked)
        unlock();
    exit(exitval);
}

lock()
{
    sprintf(lockstr, "/tmp/mixlock%d", sbuf.st_ino);
    while ((lockfd = creat(lockstr, 0)) == -1 && errno == EACCES) {
        fprintf(stderr,
            "Concurrent process lock %s, retry in 1 sec.\n", lockstr);
        sleep(1);
    }
    locked = 1;
    close(lockfd);
}

unlock()
{
    if (unlink(lockstr) == -1)
        fprintf(stderr,
            "Cannot unlink process lock %s, exiting\n", lockstr), exit(1);
    locked = 0;
}

readfile(source)
int source;
{
    int checkval, type_open;
    char *where;
    register char *here;
    char *calloc(), *malloc();

    type_open = (context == CATMIX) ? 0 : 2;
    if ((fd = open(fstring, type_open)) == -1) {
        fprintf(stderr, "File not changed: %s (no access)\n", fstring);
        return(1);
    }
        
    if ((checkval = fstat(fd, &sbuf)) == -1)
        fprintf(stderr, "File system read error %d at %s, exiting\n",
        checkval, fstring), cleanup(1);

    if (context != EDMIX || unphase)
        lock();

    if ((flen = (int)sbuf.st_size) < SMALLIM) {
        fprintf(stderr, "File not changed: %s (less than %d bytes)\n",
        fstring, SMALLIM);
        return(2);
    }

    if (((plain = calloc((unsigned)flen, 1)) == NULL) ||
        ((cipher = malloc((unsigned)flen)) == NULL))
        fprintf(stderr, "Can't allocate %lu bytes at %s, exiting\n",
            flen << 1, fstring), cleanup(1);

    source ? (where = cipher) : (where = plain);

    if (read(fd, where, flen) != flen)
        fprintf(stderr, "File read error at %s, exiting\n",
        fstring), cleanup(1);

    for (here = where + flen; --here >= where;)
        if (!*here) {
            fprintf(stderr,
                "File not changed: %s (contains NULL bytes)\n",
                fstring);
            return(3);
        }

    return(0);
}

writefile(source, outflag)
int source, outflag;
{
    long lseek();

    if (fd > 2)
        lseek(fd, 0L, 0);

    switch (source) {
        case NONE:
            break;

        case PLAIN:
            if (outflag) {
                if (write(SCREEN, plain, flen) != flen)
                    fprintf(stderr, "Can't write to stdout, exiting\n"),
                        cleanup(1);
            }
            else if (write(fd, plain, flen) != flen)
                fprintf(stderr, "Can't write file %s, exiting\n",
                    fstring), cleanup(1);
            break;

        case CIPHER:
            if (write(fd, cipher, flen) != flen)
                fprintf(stderr, "Can't write file %s, exiting\n",
                    fstring), cleanup(1);
            break;

        case SMALLBUF:
            if (read(fd, smallbuf, flen) != flen)
                fprintf(stderr, "File read error at %s, exiting\n",
                fstring), cleanup(1);
            *(smallbuf + flen) = '\0';
            if (write(SCREEN, smallbuf, flen) != flen)
                fprintf(stderr, "Can't write to stdout, exiting\n",
                    fstring), cleanup(1);
            break;
    }

    if (fd > 2) {
        close(fd);
        fd = -1;
    }

    if (context != EDMIX || !unphase)
        unlock();

    if (plain != NULL)
        free(plain);
    if (cipher != NULL)
        free(cipher);
}

/* refill chain links with original key values */
rekey()
{

    register char *here;
    int regi;

    here = kstring + klen;
    for (regi = klen; --regi;)
        key[regi].val = *--here;
    key[0].val = *--here;
}

/*  mix:
   given key byte ASCII values "a b c ... n" in circularly linked list,
   and plaintext char pointer ptr initially at plaintext[0],

        advance ptr "a" bytes;
        install its value as the first byte of cyphertext;
        zero out plaintext byte pointed to by ptr;
        decrement value of "a";

        while (not done) {
            advance to next link of key;
            advance ptr by the value of the link;
            install ptr value as the next byte of cyphertext;
            zero out plaintext byte pointed to by ptr;
            decrement value of link;
        }

    Throughout, plaintext is assumed to be a circular list of bytes:
    ptr increments beyond the buffer continue from the beginning.
    If ptr value is null (byte already assigned to cyphertext), ptr is
    incremented until the next non-null plaintext byte.
    When key link value reaches zero, the just assigned plaintext byte
    is swapped into its position.
*/

mix()
{
    register struct keychar *K;
    register char *here, *cip;
    int regi;

    rekey();

    head = plain;
    here = head + flen -1;
    tail = here -1;
    loop = head - tail -1; /* always negative */
    cip = cipher;
    K = key;

    for (regi = flen -1; --regi >= 0; ) {
        if ((here = here + K->val) > tail)
            here += loop;
        while (!*here)
            if(++here > tail)
            here = head;
        if (!--K->val)
            K->val = *here;
        K = K->next;
        *cip++ = *here;
        *here = 0;
    }
    *cip = *++tail;
}

unmix()
{
    register struct keychar *K;
    register char *here, *cip;
    int regi;

    rekey();

    head = plain;
    K = key;
    here = head + K->val;
    tail = head + flen -2;
    loop = head - tail -1; /* always negative */
    cip = cipher;

    for (regi = flen -1; --regi >= 0; ) {
        while (*here)
            if(++here > tail)
            here = head;
        *here = *cip++;
        if (!--K->val)
            K->val = *here;
        K = K->next;
        if ((here = here + K->val) > tail)
            here += loop;
    }
    *(tail +1) = *cip;
}

@\Rogue\Monster\
else
  echo "shar: Will not over write mix.c"
fi
if `test ! -s mix.man`
then
echo "x - mix.man"
cat > mix.man << '@\Rogue\Monster\'
.TH MIX 1 "" CMC
.UC 4
.SH NAME
.nh
.nf
\fBmix\ unmix\ catmix\ keymix\ edmix\fR \ \ - source code protection routines

\fBmix\fR  		- scramble a file
\fBunmix\fR		- descramble a file
\fBcatmix\fR		- print a scrambled file
\fBkeymix\fR		- print the minimum security key
\fBedmix\fR		- edit a scrambled file

.SH SYNOPSYS
.nf
.B mix\ \ \t\ [\ -k\ key\ ]\ \ files
.B unmix\t\ [\ -k\ key\ ]\ \ files
.B catmix\t\ [\ -k\ key\ ]\ \ files
.B keymix
.B edmix\t\ [\ -k\ key\ ]\ [\ -e\ exec_cmd\ ]\ \ files

.fi
.SH DESCRIPTION
The \fBmix\fR routines scramble/descramble
ASCII files based on
a supplied keyword.  Users in possession of the
key have immediate access to scrambled files
such that the scrambled nature of the files is transparent.
The routines link to a single object.
.PP
\fBMix\fR scrambles, \fBunmix\fR
descrambles the files in its argument list.  For each file in its argument list,
\fBedmix\fR descrambles the file, effects a
system call of the form \fBsystem(exec_cmd file)\fR, followed by
rescrambling the file.  \fBCatmix\fR writes a descrambled version of
its arguments to stdout.  \fBKeymix\fR prints the
"minimum security" key to stderr.
A given key affects the entire argument list.
.PP
The user normally supplies the key for the transformation mechanism.
Allowed key lengths are 1 through 128 bytes.  Longer keys are
silently truncated to 128 bytes; null keys
trigger the "minimum security" option instead.
.PP
Performance characteristics are comparable to those of the standard
\fBcrypt\fR command, while not incurring the restrictions that limit
the use of \fBcrypt\fR to the United States.
Unlike \fBcrypt\fR, the executable
is not a filter, precluding the necessity for redirecting output to
temporary files followed by a move of the temporary files to the
original files.  Also unlike \fBcrypt\fR, the scrambling effect is not the same
as the descrambling effect: two successive scramblings do not return a file
to its original form.  The command "mix myfile myfile" for example,
twice scrambles myfile; the appropriate reversal is
"unmix myfile myfile".  Still another difference with respect to \fBcrypt\fR
is that the character
set of a file scrambled by \fBmix\fR
is identical to that of the original file,
permitting remote file transfer
protocol without "control characters".
.PP
The \fBmix\fR
routines do not alter files that contain less than 256 bytes,
or files containing null (ASCII zero) bytes.  When encountering
such, a warning message is generated, without any other side effects.
A \fBmix\fR process locks the file on which it operates; concurrent
\fBmix\fR
processes competing for the same file wait until the locking
process completes the transformation and releases the lock.
.sp
.PP
.SH KEY ACQUISITION
The \fB-k key\fR command line option directly specifies the key for
the transformations, overriding the two
other methods described below.
Due to the visible records of the command line,
this option is not the
most secure alternative.
.PP
The environment variable \fBMIXKEY\fR value if non-null, is
automatically used as the key throughout the life of the user's shell.
The command "setenv MIXKEY key" assigns a value to \fBMIXKEY\fR under
the Berkeley system.  The System V equivalent is "MIXKEY=key ;
export MIXKEY".
.PP
Key acquisition is interactive in lieu of the above methods.
Echoing is turned
off and the user responds to the "Key: " prompt appearing
on stderr.
The commands reprompt
with "Again: "
under "Key: " and verify the match to avoid typos.
On a mismatch, a control-G (bel) is printed, and
the program exits without any file access.
.PP
For minimum security applications, the \fBnull key\fR
given by the user (interactively or with the command line
option \fB-k ""\fR) is supplanted with one
constructed from the effective user id of the user.  This permits
a number of individuals logging in to an environment,
easy access to information scrambled in that environment, while
excluding others.  For example, if myfile is scrambled by \fBproject\fR
using
"mix myfile < nullfile" where a redirected, empty "nullfile" supplies
a zero length key to the interactive acquisition routine, all users
logging in as \fBproject\fR
have continued access to the original "myfile" using
a null key.
Note that scrambling/descrambling with minimum security keys does not port
to other environments, unless the user provides the key previously
acquired
in the \fBoriginal\fR environment through the \fBkeymix\fR command.
.sp
.PP
.SH EDMIX COMMANDS
The default \fBsystem\fR command executed by \fBedmix\fR is the
\fBvi\fR editor.  Thus, executing
"edmix myfile.c myfile.h" commences with key acquisition, then myfile.c is
descrambled, a system("vi myfile.c") call follows, then - the possibly
modified - myfile.c is rescrambled.  Myfile.h is processed next, using the
same key.
.PP
The \fB-e exec_cmd\fR supplants the default \fBvi\fR
system call with exec_cmd.  Thus, "edmix -e emacs myfile"
allows direct editing of the unscrambled version
of a scrambled "myfile",
using the \fBemacs\fR editor.  Exec_cmd normally is
a command that takes a file name as a last argument.
Alternately, dollar ($) signs contained by exec_cmd
are expanded to the name of the currently descrambled file.
Commands longer than a word should be quoted.  Examples:
.nf

edmix -e "grep xyz" file.c file.h
edmix -e '( echo $; cat -n $ | grep xyz )  >>  lines_of_xyz' file.c file.h
.fi
.sp
.SH DATA INTEGRITY
All file reads and writes performed by the \fBmix\fR routines
are single (atomic)
operations pertaining to the length of the file, to minimize
the danger of mangled data.  User interrupts are
guaranteed to leave the entirety of a file either in its scrambled or in
its descrambled state.  However the operating system
using delayed writes to disk, may perform an incomplete flush
during a system crash and make a file unrecoverable.  For
this reason keeping some form of backup source is recommended.
.PP
Shell wild cards occasionally have the effect of cueing multiple
instances of the same file in the argument list.  The command
"mix myfile*  *.c"  for example, scrambles myfile.c twice in succession;
a later "edmix myfile.c" fills the \fBvi\fR buffer with
a first generation scrambling of myfile.c.
.PP
Loss of a key, not surprisingly, will present the user with a
substantial exercise in cryptography.
@\Rogue\Monster\
else
  echo "shar: Will not over write mix.man"
fi
if `test ! -s sp.h`
then
echo "x - sp.h"
cat > sp.h << '@\Rogue\Monster\'
/*
 * sp.h - contains combined Sbox and P permutation table
 *	      defined as left or right block (long)
 *	      Input bit ordering 5 3 2 1 0 4
 */

static unsigned long sbox_P[8][64] = {
/* SBOX 1 */ 
	  0x410100,	   0x10000,	0x40400000,	0x40410100,
	  0x400000,	0x40010100,	0x40010000,	0x40400000,
	0x40010100,	  0x410100,	  0x410000,	0x40000100,
	0x40400100,	  0x400000,	         0,	0x40010000,
	   0x10000,	0x40000000,	  0x400100,	   0x10100,
	0x40410100,	  0x410000,	0x40000100,	  0x400100,
	0x40000000,	     0x100,	   0x10100,	0x40410000,
	     0x100,	0x40400100,	0x40410000,	         0,
	         0,	0x40410100,	  0x400100,	0x40010000,
	  0x410100,	   0x10000,	0x40000100,	  0x400100,
	0x40410000,	     0x100,	   0x10100,	0x40400000,
	0x40010100,	0x40000000,	0x40400000,	  0x410000,
	0x40410100,	   0x10100,	  0x410000,	0x40400100,
	  0x400000,	0x40000100,	0x40010000,	         0,
	   0x10000,	  0x400000,	0x40400100,	  0x410100,
	0x40000000,	0x40410000,	     0x100,	0x40010100,
/* SBOX 2 */ 
	 0x8021002,	         0,	   0x21000,	 0x8020000,
	 0x8000002,	    0x1002,	 0x8001000,	   0x21000,
	    0x1000,	 0x8020002,	       0x2,	 0x8001000,
	   0x20002,	 0x8021000,	 0x8020000,	       0x2,
	   0x20000,	 0x8001002,	 0x8020002,	    0x1000,
	   0x21002,	 0x8000000,	         0,	   0x20002,
	 0x8001002,	   0x21002,	 0x8021000,	 0x8000002,
	 0x8000000,	   0x20000,	    0x1002,	 0x8021002,
	   0x20002,	 0x8021000,	 0x8001000,	   0x21002,
	 0x8021002,	   0x20002,	 0x8000002,	         0,
	 0x8000000,	    0x1002,	   0x20000,	 0x8020002,
	    0x1000,	 0x8000000,	   0x21002,	 0x8001002,
	 0x8021000,	    0x1000,	         0,	 0x8000002,
	       0x2,	 0x8021002,	   0x21000,	 0x8020000,
	 0x8020002,	   0x20000,	    0x1002,	 0x8001000,
	 0x8001002,	       0x2,	 0x8020000,	   0x21000,
/* SBOX 3 */ 
	0x20800000,	  0x808020,	      0x20,	0x20800020,
	0x20008000,	  0x800000,	0x20800020,	    0x8020,
	  0x800020,	    0x8000,	  0x808000,	0x20000000,
	0x20808020,	0x20000020,	0x20000000,	0x20808000,
	         0,	0x20008000,	  0x808020,	      0x20,
	0x20000020,	0x20808020,	    0x8000,	0x20800000,
	0x20808000,	  0x800020,	0x20008020,	  0x808000,
	    0x8020,	         0,	  0x800000,	0x20008020,
	  0x808020,	      0x20,	0x20000000,	    0x8000,
	0x20000020,	0x20008000,	  0x808000,	0x20800020,
	         0,	  0x808020,	    0x8020,	0x20808000,
	0x20008000,	  0x800000,	0x20808020,	0x20000000,
	0x20008020,	0x20800000,	  0x800000,	0x20808020,
	    0x8000,	  0x800020,	0x20800020,	    0x8020,
	  0x800020,	         0,	0x20808000,	0x20000020,
	0x20800000,	0x20008020,	      0x20,	  0x808000,
/* SBOX 4 */ 
	   0x80201,	 0x2000200,	       0x1,	 0x2080201,
	         0,	 0x2080000,	 0x2000201,	   0x80001,
	 0x2080200,	 0x2000001,	 0x2000000,	     0x201,
	 0x2000001,	   0x80201,	   0x80000,	 0x2000000,
	 0x2080001,	   0x80200,	     0x200,	       0x1,
	   0x80200,	 0x2000201,	 0x2080000,	     0x200,
	     0x201,	         0,	   0x80001,	 0x2080200,
	 0x2000200,	 0x2080001,	 0x2080201,	   0x80000,
	 0x2080001,	     0x201,	   0x80000,	 0x2000001,
	   0x80200,	 0x2000200,	       0x1,	 0x2080000,
	 0x2000201,	         0,	     0x200,	   0x80001,
	         0,	 0x2080001,	 0x2080200,	     0x200,
	 0x2000000,	 0x2080201,	   0x80201,	   0x80000,
	 0x2080201,	       0x1,	 0x2000200,	   0x80201,
	   0x80001,	   0x80200,	 0x2080000,	 0x2000201,
	     0x201,	 0x2000000,	 0x2000001,	 0x2080200,
/* SBOX 5 */ 
	 0x1000000,	    0x2000,	      0x80,	 0x1002084,
	 0x1002004,	 0x1000080,	    0x2084,	 0x1002000,
	    0x2000,	       0x4,	 0x1000004,	    0x2080,
	 0x1000084,	 0x1002004,	 0x1002080,	         0,
	    0x2080,	 0x1000000,	    0x2004,	      0x84,
	 0x1000080,	    0x2084,	         0,	 0x1000004,
	       0x4,	 0x1000084,	 0x1002084,	    0x2004,
	 0x1002000,	      0x80,	      0x84,	 0x1002080,
	 0x1002080,	 0x1000084,	    0x2004,	 0x1002000,
	    0x2000,	       0x4,	 0x1000004,	 0x1000080,
	 0x1000000,	    0x2080,	 0x1002084,	         0,
	    0x2084,	 0x1000000,	      0x80,	    0x2004,
	 0x1000084,	      0x80,	         0,	 0x1002084,
	 0x1002004,	 0x1002080,	      0x84,	    0x2000,
	    0x2080,	 0x1002004,	 0x1000080,	      0x84,
	       0x4,	    0x2084,	 0x1002000,	 0x1000004,
/* SBOX 6 */ 
	0x10000008,	   0x40008,	         0,	0x10040400,
	   0x40008,	     0x400,	0x10000408,	   0x40000,
	     0x408,	0x10040408,	   0x40400,	0x10000000,
	0x10000400,	0x10000008,	0x10040000,	   0x40408,
	   0x40000,	0x10000408,	0x10040008,	         0,
	     0x400,	       0x8,	0x10040400,	0x10040008,
	0x10040408,	0x10040000,	0x10000000,	     0x408,
	       0x8,	   0x40400,	   0x40408,	0x10000400,
	     0x408,	0x10000000,	0x10000400,	   0x40408,
	0x10040400,	   0x40008,	         0,	0x10000400,
	0x10000000,	     0x400,	0x10040008,	   0x40000,
	   0x40008,	0x10040408,	   0x40400,	       0x8,
	0x10040408,	   0x40400,	   0x40000,	0x10000408,
	0x10000008,	0x10040000,	   0x40408,	         0,
	     0x400,	0x10000008,	0x10000408,	0x10040400,
	0x10040000,	     0x408,	       0x8,	0x10040008,
/* SBOX 7 */ 
	     0x800,	      0x40,	  0x200040,	0x80200000,
	0x80200840,	0x80000800,	     0x840,	         0,
	  0x200000,	0x80200040,	0x80000040,	  0x200800,
	0x80000000,	  0x200840,	  0x200800,	0x80000040,
	0x80200040,	     0x800,	0x80000800,	0x80200840,
	         0,	  0x200040,	0x80200000,	     0x840,
	0x80200800,	0x80000840,	  0x200840,	0x80000000,
	0x80000840,	0x80200800,	      0x40,	  0x200000,
	0x80000840,	  0x200800,	0x80200800,	0x80000040,
	     0x800,	      0x40,	  0x200000,	0x80200800,
	0x80200040,	0x80000840,	     0x840,	         0,
	      0x40,	0x80200000,	0x80000000,	  0x200040,
	         0,	0x80200040,	  0x200040,	     0x840,
	0x80000040,	     0x800,	0x80200840,	  0x200000,
	  0x200840,	0x80000000,	0x80000800,	0x80200840,
	0x80200000,	  0x200840,	  0x200800,	0x80000800,
/* SBOX 8 */ 
	 0x4100010,	 0x4104000,	    0x4010,	         0,
	 0x4004000,	  0x100010,	 0x4100000,	 0x4104010,
	      0x10,	 0x4000000,	  0x104000,	    0x4010,
	  0x104010,	 0x4004010,	 0x4000010,	 0x4100000,
	    0x4000,	  0x104010,	  0x100010,	 0x4004000,
	 0x4104010,	 0x4000010,	         0,	  0x104000,
	 0x4000000,	  0x100000,	 0x4004010,	 0x4100010,
	  0x100000,	    0x4000,	 0x4104000,	      0x10,
	  0x100000,	    0x4000,	 0x4000010,	 0x4104010,
	    0x4010,	 0x4000000,	         0,	  0x104000,
	 0x4100010,	 0x4004010,	 0x4004000,	  0x100010,
	 0x4104000,	      0x10,	  0x100010,	 0x4004000,
	 0x4104010,	  0x100000,	 0x4100000,	 0x4000010,
	  0x104000,	    0x4010,	 0x4004010,	 0x4100000,
	      0x10,	 0x4104000,	  0x104010,	         0,
	 0x4000000,	 0x4100010,	    0x4000,	  0x104010,
};
@\Rogue\Monster\
else
  echo "shar: Will not over write sp.h"
fi
if `test ! -s xorcrypt.Description`
then
echo "x - xorcrypt.Description"
cat > xorcrypt.Description << '@\Rogue\Monster\'

Herewith the source code for "xorcrypt", a quick and simple program
for file encryption.  Characters (bytes) of the plaintext are XORed
with the output of a (pseudo) random number genrator.  The additive
number generator Y[n] = Y[n-24] + Y[n-55] is used; among other
properties, it has a large amount of state information, hence a big
"key space".

Here are timings measured on a SparcStation 1, which approximates a Sun4.
Times are as reported by time(1) and are averages of four runs.

    Length of file encrypted           CPU time      Wallclock Time
 --------------------------------------------------------------------
         1,000,000 bytes                8.5 sec         15.0 sec
         5,000,000 bytes               40.0 sec         57.7 sec
        10,000,000 bytes               78.9 sec        104.7 sec

Doing linear regression,         CPU time ~=~ 0.76 + (7.82e-6)*(filelength)
                           Wallclock time ~=~ 6.10 + (9.94e-6)*(filelength)

*****************************************************************************
* Summarizing,    xorcrypt achieved 128,000 characters per CPU second       *
*                                   101,000 characters per wallclock second *
*****************************************************************************
@\Rogue\Monster\
else
  echo "shar: Will not over write xorcrypt.Description"
fi
if `test ! -s xorcrypt.c`
then
echo "x - xorcrypt.c"
cat > xorcrypt.c << '@\Rogue\Monster\'
/* simple file encryption program    Public Domain    18 Sept 1990 */


/* A user-supplied key is employed to construct the vector of 55 seeds */
/* to the additive random number generator y[i] = y[i-25] + y[i-55]    */
/* Knuth discusses this generator in vol 2. sec 3.2.2, Algorithm A.    */

/* A linear congruential generator hashes the users key into the 55    */
/* initial y[n] seeds for the additive random number generator.  After */
/* this initialization, the random number generator creates random     */
/* bytes which are XORed with the plaintext to form the ciphertext.    */
/* Decryption is identical, since for xor, encr(encr(x)) == x          */


#include <stdio.h>


/* global variables */
  int y[70] ;
  int jv;



/* additive random number generator from Knuth */
/*    global vector "y" holds previous vals    */

int kran()
{
  static int j = 24;
  static int k = 55 ;
  int l ;

  y[k] = (y[k] + y[j]) ;
  if(y[j] < 0) y[j] = 0 - y[j] ;
  if(y[k] < 0) y[k] = 0 - y[k] ;
  j = j - 1 ;
  k = k - 1 ;
  if(j <= 0) j = 55 ;
  if(k <= 0) k = 55 ;
  if(y[k] < 0) y[k] = 0 - y[k] ;
  l = y[k] ;
  return(l) ;
}



/* the jumble-maker function ... use a linear congruential sequence */
int jran()
{
  int l ;

  l = jv ;
  l = 907620093 + (719685677 * l) ;
  if(l < 0) l = 0 - l ;
  jv = l ;
  return(l);
}





main(argc, argv)
     char **argv;
     int argc;
{

  int i, j, k, l;
  char c ;
  char pwa[100], pwb[100] ;
  char fna[100], fnb[100] ;

  FILE *fpin, *fpout, *fopen() ;


  /* initialize Knuth rand array */

  y[0]  = 2348715845;
  y[1]  = 1665052570;
  y[2]  = 796063141;
  y[3]  = 2390298980;
  y[4]  = 2079021256;
  y[5]  = 2596604540;
  y[6]  = 1508146164;
  y[7]  = 2625542359;
  y[8]  = 2223371122;
  y[9]  = 3676765191;
  y[10] = 1906462346;
  y[11] = 3413673518;
  y[12] = 2728255651;
  y[13] = 1940057027;
  y[14] = 794662019;
  y[15] = 1620129301;
  y[16] = 1264837106;
  y[17] = 65203769;
  y[18] = 4059781360;
  y[19] = 2503345998;
  y[20] = 3784670567;
  y[21] = 522121999;
  y[22] = 95643657;
  y[23] = 368857307;
  y[24] = 1152087321;
  y[25] = 862814598;
  y[26] = 558599604;
  y[27] = 3544928103;
  y[28] = 1434957517;
  y[29] = 1916900830;
  y[30] = 319033340;
  y[31] = 1699592126;
  y[32] = 2620222628;
  y[33] = 2324637842;
  y[34] = 2105951963;
  y[35] = 2201325727;
  y[36] = 2252826763;
  y[37] = 1283343040;
  y[38] = 1360358289;
  y[39] = 2548429334;
  y[40] = 704311033;
  y[41] = 769424534;
  y[42] = 3596700434;
  y[43] = 2706354780;
  y[44] = 14282683;
  y[45] = 1578471924;
  y[46] = 1080158821;
  y[47] = 2894994679;
  y[48] = 850918056;
  y[49] = 4025988341;
  y[50] = 3661851959;
  y[51] = 3007918068;
  y[52] = 350208515;
  y[53] = 3928308459;
  y[54] = 3438283319;
  y[55] = 404867971;
  y[56] = 32112902;
  y[57] = 3120700983;
  y[58] = 161283647;
  y[59] = 4280346983;
  y[60] = 2427798542;
  y[61] = 24;
  y[62] = 55 ;



agai:
  printf("\ntype the Encryption Password: ");
  i = scanf("%s", pwa);
  printf("Verify:                       ");
  i = scanf("%s", pwb);
  if( 0 != strcmp(pwa, pwb) ) { printf("\nNOPE"); goto agai; }



/* Set the seed "jv" of the linear congruential sequence generator */
/* to a value uniquely determined by the encryption password "pwa" */
jv = 31415 ;
j = strlen(pwa);
for(i=0; i<j; i++)
  {
    c = pwa[i] ;
    k = jran() ;
    k = c ;
    jv += k ;    
  }


printf("\ninput filename:  ");
i = scanf("%s", fna);
printf("output filename: ");
i = scanf("%s", fnb);



/* run the linear congruential generator for 200 iterations */
/*  (theres no good reason to do this at all; just fun)     */
for(i=0; i<200; i++) { k = jran(); }



/* modify all 60 entries of the Knuth random table                  */
/*      generate a Knuth rand  k  from 0 to 99                      */
/*      run the jumbler for  k  iterations                          */
/*      replace the Knuth table entry with the next jumbler output  */
/* when all done, Knuth randgen is now a function of encrypt passwd */
for(i=0; i<60; i++)
  {
    k = (kran()) % 100 ;
    for(j=0; j<k; j++) { l = jran(); }
    l = jran() ;
    y[i] = l ;
  }




/* run the Knuth additive generator for 100000 iterations   */
/*     to let it "smooth itself out" and also to give it a  */
/*     good chance to schmeer and modify all 60 entries     */
/* (theres no good reason to do this at all; just fun)      */
for(i=0; i<100000; i++) { l = kran(); }





if ((fpin = fopen(fna, "r")) == NULL)
  { printf("\nERROR cannot open input file %s\n", fna); exit(-1); }

if ((fpout = fopen(fnb, "w")) == NULL)
  { printf("\nERROR cannot open output file %s\n", fnb); exit(-1); }


while( (i=getc(fpin)) != EOF )
  {
    j = ( (kran()) >> 3 ) & 0x000000ff ;
    k = (i ^ j) ;
    c = k ;
    putc(c, fpout) ;
  }


} /* end of main() */
@\Rogue\Monster\
else
  echo "shar: Will not over write xorcrypt.c"
fi
echo "Finished archive 2 of 2"
# to concatenate archives, remove anything after this line
exit 0
-- 
 -- Mark Johnson	
 	MIPS Computer Systems, 930 E. Arques M/S 2-02, Sunnyvale, CA 94086
	(408) 524-8308    mark@mips.com  {or ...!decwrl!mips!mark}