home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
encrypt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-21
|
2KB
|
54 lines
/*********
*
* ENCRYPT.C
*
* by Leonard Zerman, Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: ENCRYPT( <string>, <password> )
* Return: <expC> of <string> encoded 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 encrypt()
{
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 encrypt */