void Gen_Encrypt(STRING in, STRING out) { /* * The encryption routine has been adapted from the MicroEMACS encryption * function written by Dana Hoggatt, known as DLH-POLY-86-B CIPHER. */ register short cc; /* Current character */ long key = 0; /* 29-bit cipher key */ short salt = 0; /* Spice for key */ if (in) { short len = strlen(in); while (len--) { cc = *in; if ((cc >= ' ') && (cc <= '~')) /* Printable? */ { key &= 0x1FFFFFFFL; /* strip off overflow */ if (key & 0x10000000L) key ^= 0x0040A001L; /* feedback */ cc = mod95((int)(key % 95) - (cc - ' ')) + ' '; if (++salt >= 20857) salt = 0; key <<= 1; key += cc + *in + salt; } in++; *out++ = cc; } *out = '\0'; } }
static void ue_crypt (register char *bptr, register int len) /* register char *bptr; buffer of characters to be encrypted */ /* register int len; number of characters in the buffer */ { register int cc; /* current character being considered */ static long key = 0; /* 29 bit encryption key */ static int salt = 0; /* salt to spice up key with */ if (!bptr) { /* is there anything here to encrypt? */ key = len; /* set the new key */ salt = len; /* set the new salt */ return; } while (len--) { /* for every character in the buffer */ cc = *bptr; /* get a character out of the buffer */ /* only encipher printable characters */ /* was: if ((cc >= ' ') && (cc <= '~')) */ if (isprint (cc)) { /** If the upper bit (bit 29) is set, feed it back into the key. This assures us that the starting key affects the entire message. **/ key &= 0x1FFFFFFFL; /* strip off overflow */ if (key & 0x10000000L) { key ^= 0x0040A001L; /* feedback */ } /** Down-bias the character, perform a Beaufort encryption, and up-bias the character again. We want key to be positive so that the left shift here will be more portable and the mod95() faster **/ cc = mod95 ((int) (key % 95) - (cc - ' ')) + ' '; /** the salt will spice up the key a little bit, helping to obscure any patterns in the clear text, particularly when all the characters (or long sequences of them) are the same. We do not want the salt to go negative, or it will affect the key too radically. It is always a good idea to chop off cyclics to prime values. **/ if (++salt >= 20857) { /* prime modulus */ salt = 0; } /** our autokey (a special case of the running key) is being generated by a weighted checksum of clear text, cipher text, and salt. **/ key = key + key + cc + *bptr + salt; } *bptr++ = cc; /* put character back into buffer */ } return; }