> * ********************************************* > * FUNCTION EncryptPass > * Author Steve Ruhl > * Written March 14, 1996 > * Description > * Encrypt passwords > * Passed: > * lcCryptStr CHAR Password to encrypt / decrypt > * lcWordLen NUM Length of password string > * Returns: > * CHAR Encrypted string > * NOTES Function converts the password to all UPPER case characters before > * encrypting it. > * If the value to be encrypted is all blanks, or is a null string, > * it is returned as all blanks as well, rather than being actually > * encrypted. > * When encrypting a string, the string to be encrypted is padded > * to the length specified in the <tnWordLength> parameter. The > * string returned is actually one character longer than the > * <tnWordLength>, because the "offset character" for decrypting the > * first actual character of the string is added to the front of > * the string. > * Usage: > * lcVar = EncryptPass( tcPasswordString, tnWordLength ) > * ********************************************* >FUNCTION EncryptPass( tcPasswordString,tnWordLength ) > > LOCAL lcWrkStr && Temp storage for encrypted string > LOCAL lcWrkChar && Character buing encrypted > LOCAL lcWrkPass && Encrypted password > LOCAL lcOffset && Offset character > LOCAL llDone && Done flag > LOCAL lnI && Loop counter > > IF !EMPTY( tcPasswordString ) > lcWrkStr = PADR( UPPER( tcPasswordString ), tnWordLength ) > STORE '' TO lcWrkPass, lcWrkChar > > *---Generate a random ascii code for the offset character > lcOffset = MOD( RAND( -1 ) * 10000, 255 ) + 1 > > lcWrkPass = CHR( lcOffset ) && Store offset character as first character in the translated string > > FOR lnI=1 TO tnWordLength && Parse characters from input string > lcWrkChar = SUBSTR( lcWrkStr, lnI, 1 ) > > *---The character is encrypted as follows: > * 1: Take its ASCII value > * 2: Add value of the offset > * 3: MOD this new number by 255 to make sure it is a legal ASCII value > * 4: Convert it back into an ASCII character > > lcWrkChar = CHR( MOD( ASC( lcWrkChar ) + lcOffset, 255 ) + 1 ) > lcWrkPass = lcWrkPass + lcWrkChar > > *---The ASCII value of this encrypted character is then used as the > *---offset for the next character. In this way, the offset value > *---changes for each character, making it harder to decrypt. > lcOffset = ASC( lcWrkChar ) > ENDFOR > > ELSE && If string to be encrypted is blank > lcWrkPass = SPACE( tnWordLength + 1 ) && return blanks as the encrypted value. > ENDIF > RETURN (lcWrkPass) >ENDFUNC > >* ********************************************* >* FUNCTION DecryptPass >* Author Steve Ruhl >* Written March 14, 1996 >* Description >* Decrypt passwords >* Passed: >* lcCryptStr CHAR Password to decrypt >* lcWordLen NUM Length of password string >* Returns: >* CHAR Decrypted string >* NOTES Function always returns all characters in UPPER case. >* Usage: >* lcVar = DecryptPass( tcPasswordString, tnWordLength ) >* ********************************************* >FUNCTION DecryptPass( tcPasswordString,tnWordLength ) > > LOCAL lcWrkStr > LOCAL lcWrkChar > LOCAL lcWrkPass > LOCAL lcOffset > LOCAL llDone > LOCAL lnI > > IF !EMPTY( tcPasswordString ) > > STORE '' TO lcWrkPass, lcWrkChar > lcWrkStr = SUBSTR( tcPasswordString, 2 ) > tnWordLength = LEN( tcPasswordString ) > llDone = .F. > > *---Determine offset value of first character > lcOffset = ASC( tcPasswordString ) > > *---Note first character is skipped because it is only the "offset > * character" for the first character of the actual string > FOR lnI = 2 TO tnWordLength > lcWrkChar = SUBSTR( tcPasswordString, lnI, 1 ) > > IF ASC( lcWrkChar ) <= lcOffset > lcWrkPass = lcWrkPass + CHR( 255 + ASC( lcWrkChar ) - lcOffset - 1 ) > ELSE > lcWrkPass = lcWrkPass + CHR( ASC( lcWrkChar ) - lcOffset - 1 ) > ENDIF > > lcOffset = ASC( lcWrkChar ) > > ENDFOR > ELSE > lcWrkPass = SPACE( tnWordLength ) > ENDIF > > RETURN (lcWrkPass) >ENDFUNC > >