home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / GameSmith1-Hisoft-System.DMS / in.adf / GDS_System.lha / cydec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-17  |  1.5 KB  |  68 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "cydec_proto.h"
  4.  
  5. #define CYPHER_KEY    50
  6.  
  7. static int cypher_len;
  8. static unsigned char encrypt_key,decrypt_key;
  9. static unsigned char *cypher_id="GameSmith Encrypted";
  10.  
  11. /*********************************************************************/
  12.  
  13. __stdargs int gs_identify_cypher(int len, unsigned char *cypher)
  14.  
  15. {
  16.     cypher_len=strlen(cypher_id);
  17.     if (cypher_len & 1)        /* cypher length MUST be even number */
  18.         cypher_len++;
  19.     if (len != cypher_len)
  20.         return(0);                /* cypher unrecognized */
  21.     if (strcmp(cypher_id,cypher))
  22.         return(0);                /* cypher unrecognized */
  23.     decrypt_key=CYPHER_KEY;    /* init decryption key */
  24.     return(1);                    /* OK! We know that one */
  25. }
  26.  
  27. /*********************************************************************/
  28.  
  29. __stdargs unsigned char *gs_cypher_block(int *len, int type)
  30.  
  31. {
  32.     encrypt_key=CYPHER_KEY;    /* init encryption key */
  33.     *len=strlen(cypher_id);
  34.     if (*len & 1)                /* cypher length MUST be even number */
  35.         (*len)++;
  36.     return(cypher_id);
  37. }
  38.  
  39. /*********************************************************************/
  40.  
  41. __stdargs void gs_encrypt_data(int len, unsigned char *data)
  42.  
  43. {
  44.     int cnt;
  45.  
  46.     for (cnt=0; cnt < len; cnt++)
  47.         {
  48.         data[cnt]=data[cnt]+encrypt_key;
  49.         encrypt_key=data[cnt];
  50.         }
  51. }
  52.  
  53. /*********************************************************************/
  54.  
  55. __stdargs void gs_decrypt_data(int len, unsigned char *data)
  56.  
  57. {
  58.     int cnt;
  59.     unsigned char temp;
  60.  
  61.     for (cnt=0; cnt < len; cnt++)
  62.         {
  63.         temp=data[cnt];
  64.         data[cnt]=data[cnt]-decrypt_key;
  65.         decrypt_key=temp;
  66.         }
  67. }
  68.