home *** CD-ROM | disk | FTP | other *** search
- /* #include "cipher.c"
-
- USAGE: set_crypt(keystring, seedinteger); < string ciphers >
- encode( target1string );
- encode( target2string );
- ... etc.
-
- set_crypt(keystring, seedinteger);
- decode( target1string );
- decode( target2string );
- ... etc.
-
- OR: set_crypt(key, seed); < single-character ciphers >
- c0 = cryptic(c0);
- c1 = cryptic(c1);
- ... ;
- cN = cryptic(cN);
-
- set_crypt(key, seed);
- c0 = uncrypt(c0);
- c1 = uncrypt(c1);
- ... ;
- cN = uncrypt(cN);
-
- */
-
-
-
- /*=======================================================================*/
- /* An Elementary Holocryptic Cipher: */
- /* The following is a variation on what was described as Hogg's code */
- /* from World War I in the Sept. 1984 FOGHORN (First Osborne Group). */
- /* The point of the additional bells & whistles is to make the entire */
- /* text of the Zaphod Adventure as nearly holocryptic as possible. */
- /* It works by spinning the key modulus on successive lines; so, while */
- /* line appearance is preserved, analysis of the characters of each */
- /* line depends on recovering the initial LCG seed, as well as the key. */
- /* Bright adventurers are discouraged from trying to cheat by dumping */
- /* the Zaphod files, hopefully. -D. C. Oshel, 10/6/84 */
- /*=======================================================================*/
-
- static int kloc, klen;
- static unsigned kRNDlxo;
- static char kQey[32];
-
- set_crypt(key,seed) char *key; int seed; {
-
- static int i;
-
- i = 0;
- while (*key, i < 31) kQey[i++] = *key++; /* local copy of the key */
- kQey[i] = '\0';
- kRNDlxo = seed; klen = strlen(kQey); Krandi();
-
- } /* end: set_crypt */
-
- encode(p) char *p; {
-
- while (*p) *p = cryptic(*p++); Krandi();
-
- } /* end: encode */
-
- decode(p) char *p; {
-
- while (*p) *p = uncrypt(*p++); Krandi();
-
- } /* end: decode */
-
- Krandi() {
-
- kRNDlxo = 2053 * kRNDlxo + 13849; /* a long-period LCG */
- kloc = (abs( kRNDlxo )) % klen;
-
- } /* end: Krandi */
-
- cryptic( c ) int c; {
-
- if ( c > 31 && c < 127 ) {
- c = ( (c - 32) + (kQey[kloc++] - 32) ) % 95;
- kloc %= klen;
- return ( c + 32 );
- }
- else return ( c );
-
- } /* end: cryptic */
-
- uncrypt( c ) int c; {
-
- if ( c > 31 && c < 127 ) {
- c -= 32; c -= kQey[kloc++] - 32;
- kloc %= klen;
- if ( c < 0 ) c += 95;
- return ( c + 32 );
- }
- else return ( c );
-
- } /* end: uncrypt */
-
- /* end of "cipher.c" */