Newsgroups: rec.arts.int-fiction
Path: gmd.de!jvnc.net!yale.edu!yale!gumby!wupost!uunet!psinntp!dg-rtp!webo!dg-webo!pds
From: pds@lemming.webo.dg.com (Paul D. Smith)
Subject: Re: Encrypted hints 
Sender: usenet@webo.dg.com (Usenet Administration)
Message-ID: <PDS.92Dec8132702@lemming.webo.dg.com>
In-Reply-To: librik@cory.Berkeley.EDU's message of Tue, 8 Dec 1992 01:39:13 GMT
Date: 08 Dec 92 18:27:01 GMT
To: librik@cory.Berkeley.EDU (David Librik)
Lines: 232
References: <1ftktqINNjfu@life.ai.mit.edu> <1ftnlgINNkp4@life.ai.mit.edu>
	<librik.723701575@cory.Berkeley.EDU> <1992Dec7.090513.672@nwnexus.WA.COM>
	<librik.723778753@cory.Berkeley.EDU>
Organization: NSDD/ONSD, Data General Corp., Westboro, MA
Lines: 232

[] Regarding Re: Encrypted hints ; you wrote:

    dl> Well, come up with a cipher that people can't do in their
    dl> heads.  That's not too tough.  As for "a royal pain" -- that's
    dl> why the cipher key was printed at the bottom of every page.

Heck, I wrote a short program to do this; it's trivial.  IMHO there's
no need for a complex cipher; a=z (or whatever) is fine.  I mean, sure
some people could probably do it in their heads, but no one's going to
be able to look at the sentence and translate it instantly, just as if
it was plaintext.

As long as it's not immediately obvious, it serves the purpose IMHO.

Here's a simple encryption/decryption program.  It should be very
portable.  Use it as you like (or junk it :) Don't forget to strip my
.sig at the end; unfortunately inews adds it for me :(

For a brief description, decrypt the following :) -- try using:

    % cat <txt> | ./hcrypt -

or, if you can cut/paste:

    % ./hcrypt - > output
    <paste text here>
    % cat output

-26
:!7E59 9,0(8 , +/-3 ,7;A2(39 ,8 9:( )#789 ,7;G 9:(3 9:( 9(D9H  9:(
3A2.(7 <3> #8 ,??(? 94/8A.97,!9(? )742 (,!: !:,7 #3 9:( 9(D9G ,3? 9:(
7(8A19 #8 1440(? A5 #3 ,3 #39(73,1 9,.1( 94 ;(9 9:( 7(8A19H

!:,78 349 #3 9:( 9,.1( ,7( 1()9 ,143(H  9:( 4A95A9 #8 57()#D(? C#9:
9:( #3B(78( 45(7,9#43G 84 #9'8 8#251( 94 (3!7E59 (,!: :#39 C#9: ,
?#))(7(39 4))8(9 #) ?(8#7(?H

----- 8>< snip, snip ><8 ------------------------------------------------------
/* hcrypt.c - extremely simple encrypt/decrypt for text
 *
 *      Copyright (C) 1992 Paul D. Smith
 *
 *      hcrypt is free software; you can redistribute it and/or modify it
 *      under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 1, or (at your option)
 *      any later version.
 *
 *      hcrypt is distributed in the hope that it will be useful, but WITHOUT
 *      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 *      License for more details.
 *
 *      To get a copy of the GNU General Public License, write to the Free
 *      Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <stdio.h>
#include <ctype.h>

/*
 * The text string contains the chars which will be encrypted;
 * anything not in this string will be printed unchanged.
 *
 * Note that the digits and letters must come all together and in the
 * proper order.  Any other chars should be added with the
 * punctuation, and can be in any order.
 */
#define TEXT        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,.!?();:-#$"
#define TEXT_LEN    (sizeof(TEXT)-1)

#define DIG_OFF     0                       /* start of digits in TEXT */
#define ALPHA_OFF   10                      /* start of letters in TEXT */
#define PUNCT_OFF   36                      /* start of punctuation in TEXT */

extern int atoi();

int main(argc, argv)
int argc;
char *argv[];
{
    char line[81];
    char **cpp;
    char *cp;
    char *text = TEXT;
    int offset, neg=0;

    /*
     * Make sure the command line looks reasonable...
     */
    if ((argc < 2) || ((argc < 3) && strcmp(argv[1], "-")))
    {
        fprintf(stderr, "Usage: %s [- | +|-n <text> ...]\n", argv[0]);
        exit(1);
    }

    /*
     * Find the absolute value of the offset; set NEG if it's negative
     * Set up to read from the command line, or from stdin.
     */
    if (argc > 2)
    {
        cp = argv[1];
        cpp = &argv[1];
    }
    else
    {
        fgets(line, 81, stdin);
        for (cp = line; isspace(*cp) && (*cp != '\0'); ++cp)
        {}
    }

    if ((cp[0] != '+') && (cp[0] != '-'))
    {
        fprintf(stderr, "%s: Invalid offset syntax: `%s'\n", argv[0], cp);
        exit(1);
    }

    offset = atoi(&cp[1]);
    if (offset > TEXT_LEN)
    {
        offset %= TEXT_LEN;
        fprintf(stderr,
                "%s: warning: offset too large--using mod of max (%d) = %d\n",
                argv[0], TEXT_LEN, offset);
    }
    if (!offset)
    {
        fprintf(stderr, "%s: No conversion done: offset is 0\n", argv[0]);
        exit(0);
    }
    if (cp[0] == '-')
        neg = 1;

    /*
     * Print the decoding info...
     */
    printf("%c%d ", neg ? '+' : '-', offset);

    /*
     * Now loop through the input, converting it as necessary.
     */
    cp += 2;
    while (isdigit(*cp))
        ++cp;
    while (isspace(*cp))
        ++cp;

    while (1)
    {
        int c;

        /*
         * Get the next char, either from the command line or stdin
         */
        if (argc > 2)
        {
            if (*cp != '\0')
                ++cp;
            else
            {
                if (*(++cpp) == NULL)
                    break;
                cp = *cpp;
            }

            c = *cp == '\0' ? ' ' : *cp;
        }
        else
        {
            if (*cp == '\0')
            {
                if (fgets(line, 81, stdin) == NULL)
                    break;
                cp = line;
            }

            c = *(cp++);
        }

        /*
         * Figure out the char's offset in the TEXT array
         */
        if (isalpha(c))
            c = ((islower(c) ? toupper(c) : c) - 'A') + ALPHA_OFF;
        else if (isdigit(c))
            c = (c - '0') + DIG_OFF;
        else
        {
            char *tp;
            
            for (tp = text+PUNCT_OFF; (*tp != '\0') && (*tp != c); ++tp)
            {}

            /*
             * If it's not in the array, then just print it and continue
             */
            if (*tp == '\0')
            {
                putchar(c);
                continue;
            }
            c = tp - text;
        }

        /*
         * Encrypt and print it
         */
        if (neg)
        {
            c -= offset;
            if (c < 0)
                c += TEXT_LEN;
        }
        else
            c = (c + offset) % TEXT_LEN;
        
        putchar(text[c]);
    }

    putchar('\n');
    exit(0);
    return (0);
}
--

                                                                paul
-----
 ------------------------------------------------------------------
| Paul D. Smith                          |    paul_smith@dg.com    |
| Data General Corp.                     | pds@lemming.webo.dg.com |
| Network Systems Development Division   |                         |
| Open Network Systems Development       |   "Pretty Damn S..."    |
 ------------------------------------------------------------------
