home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / encrypt.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  103 lines

  1. /*
  2.  * File......: ENCRYPT.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_ENCODE()
  24.  *  $CATEGORY$
  25.  *      Security
  26.  *  $ONELINER$
  27.  *      Encode a string
  28.  *  $SYNTAX$
  29.  *      GT_Encode( cString )
  30.  *  $ARGUMENTS$
  31.  *      cString - String to be encoded
  32.  *  $RETURNS$
  33.  *      The encoded representation of cString.
  34.  *  $DESCRIPTION$
  35.  *      Uses an encryption algorithm to encode a string that can later be
  36.  *      decoded using GT_Decode()
  37.  *  $EXAMPLES$
  38.  *
  39.  *  $SEEALSO$
  40.  *
  41.  *  $INCLUDE$
  42.  *      GT_LIB.CH
  43.  *  $END$
  44.  */
  45.  
  46. *
  47. #include "GT_lib.ch"
  48.  
  49. FUNCTION GT_Encode( cString )
  50.  
  51. /*****************************************************************************
  52.  Purpose - Encode a string
  53.  Returns - Encoded string
  54.  Author  - Martin Colloby
  55.  Created - 3/3/92
  56.  Edited  - 25/4/92 by Martin Colloby - Tidied up
  57. ******************************************************************************
  58.  Parameters - cString - String to encode
  59.  Privates   - None
  60.  Locals     - None
  61.  Externals  - None
  62. *****************************************************************************/
  63.  
  64. RETURN( GT_Encrypt( ALLTRIM( cString ) ) )
  65. *
  66. STATIC FUNCTION GT_Encrypt( cString )
  67.  
  68. /*****************************************************************************
  69.  Purpose - Encrypt a string
  70.  Returns - Encrypted string
  71.  Author  - Martin Colloby
  72.  Created - 3/3/92
  73.  Edited  - 25/4/92 by Martin Colloby - Tidied up
  74. ******************************************************************************
  75.  Parameters - cString - String to encrypt
  76.  Privates   - None
  77.  Locals     - cChar   - Current character
  78.               cRetStr - String to return
  79.               nCount  - Count of characters processed
  80.               nInt    - Integer part of character code
  81.               nLength - Length of cString
  82.               nRem    - Remainder of character code
  83.  Externals  - None
  84. *****************************************************************************/
  85.  
  86. LOCAL cChar   := ""
  87. LOCAL cRetStr := ""
  88. LOCAL nCount  := 1
  89. LOCAL nInt    := 0
  90. LOCAL nLength := LEN( cString ) * 2
  91. LOCAL nRem    := 0
  92.  
  93. DO WHILE nCount <= nLength
  94.     cChar := SUBSTR( cString , nCount , 1 )
  95.     nInt := INT( ASC( cChar ) / 17 )
  96.     nRem := ASC( cChar ) % 17               // Modulus 17
  97.     cRetStr += ( CHR( nInt ) + CHR( nRem ) )
  98.     nCount++
  99. ENDDO
  100.  
  101. RETURN( cRetStr )
  102. *
  103.