home *** CD-ROM | disk | FTP | other *** search
- /*********
- *
- * DECRYPT.C
- *
- * by Leonard Zerman, Tom Rettig
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: DECRYPT( <string>, <password> )
- * Return: <expC> of <string> decoded according to <password>.
- * Return string will be same length as <string>.
- * Unchanged <string> if <password> is less than 3 characters.
- * Note..: Both parameters are <expC>.
- *********/
-
- #include "trlib.h"
-
- TRTYPE decrypt()
- {
- char *pwstr, *instr, *ret;
- int len, pwlen;
-
- if ( PCOUNT == 2 && ISCHAR(1) && ISCHAR(2) )
- {
- instr = _parc(1); /* pointer to string */
- pwstr = _parc(2); /* pointer to password */
- len = _tr_strlen(instr); /* length of string */
- pwlen = _tr_strlen(pwstr); /* length of password */
- /* allocate memory for return */
- ret = _tr_allocmem( (unsigned)( len + 1 ) );
-
- if ( !( ret ) || pwlen < PW_MIN_LEN ) /* if allocation error */
- { /* or pwlen < 3 characters */
- _retc( instr ); /* return without changing anything */
- return;
- }
-
- _retc( _tr_crypt( instr, pwstr, ret ) ); /* return decrypted string */
- _tr_freemem( ret,(unsigned)( len + 1 )); /* free allocated memory */
-
- }
- else
- {
-
- if ( ISCHAR(1) ) /* if error on parameters passed */
- _retc( _parc(1) ); /* return unchanged */
- else
- _retc( NULLS ); /* if wrong type of parameters are sent */
-
- return;
- }
- }
- /* eof decrypt */
-