home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ARC521-2.ZIP / ARCCODE.C < prev    next >
C/C++ Source or Header  |  1989-12-29  |  1KB  |  44 lines

  1. /*
  2.  * $Header: arccode.c,v 1.1 88/06/01 15:15:58 hyc Locked $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCCODE
  7.  *
  8.  * Version 1.02, created on 01/20/86 at 13:33:35
  9.  *
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  *
  12.  * By:  Thom Henderson
  13.  *
  14.  * Description: This file contains the routines used to encrypt and decrypt data
  15.  * in an archive.  The encryption method is nothing fancy, being just a
  16.  * routine XOR, but it is used on the packed data, and uses a variable length
  17.  * key.  The end result is something that is in theory crackable, but I'd
  18.  * hate to try it.  It should be more than sufficient for casual use.
  19.  *
  20.  * Language: Computer Innovations Optimizing C86
  21.  */
  22. #include <stdio.h>
  23. #include "arc.h"
  24.  
  25. static char    *p;        /* password pointer */
  26.  
  27. void
  28. setcode()
  29. {                /* get set for encoding/decoding */
  30.     p = password;        /* reset password pointer */
  31. }
  32.  
  33. unsigned char
  34. code(c)                /* encode some character */
  35.     char            c;    /* character to encode */
  36. {
  37.     if (p) {        /* if password is in use */
  38.         if (!*p)    /* if we reached the end */
  39.             p = password;    /* then wrap back to the start */
  40.         return c ^ *p++;/* very simple here */
  41.     } else
  42.         return c;    /* else no encryption */
  43. }
  44.