2012/09/16

** foxpro simple encrypt code ** function code from netware
select userdb
scan
s2=aencode(password)
s3=adecode(s2)
? password,s2,s3
endscan


**********************************************************************
* Program....: AEnCode.PRG
* Compiler...: Visual FoxPro 06.00.8492.00 for Windows
* Abstract...: Encrypt a Password
**********************************************************************
FUNCTION aencode(tcKeyWord)
LOCAL lcRaw, lnVar, lcEnc
IF TYPE('tcKeyWord') # "C" OR EMPTY(tcKeyWord)
*** Must pass a character key to this process
ERROR( "9000: A Character string is the required parameter for AEnCode" )
RETURN ""
ENDIF
lcRaw = UPPER(ALLTRIM(tcKeyWord)) && Keyword
lnVar = INT(RAND() * 10) && Random Number Key: 0 - 9
lcEnc = ALLTRIM(STR(lnVar)) && Encrypted string starts with key #
*** Parse the Keyword and encrypt each character
*** Using its ASCII code + 17 + Random Key + Position in Keyword
FOR lnCnt = 1 TO LEN(lcRaw)
lcChar = SUBSTR(lcRaw, lnCnt,1)
lcEnc = lcEnc + CHR( ASC(lcChar) + 17 + lnVar + lnCnt + 1)
NEXT
RETURN lcEnc
**********************************************************************
* Program....: ADeCode.PRG
* Compiler...: Visual FoxPro 06.00.8492.00 for Windows
* Abstract...: Decodes a password encrypted with AEnCode()
**********************************************************************
FUNCTION adecode(tcKeyWord)
LOCAL lcRaw, lnVar, lcEnc
IF TYPE('tcKeyWord') # "C" OR EMPTY(tcKeyWord)
*** Must pass a character key to this process
ERROR( "9000: An Encrypted string is the required parameter for ADeCode" )
RETURN ""
ENDIF
lcEnc = ALLTRIM(tcKeyWord) && Keyword
lnVar = VAL(LEFT(lcEnc,1)) && Encryption Key
lcRaw = "" && Decoded Password
*** Parse the Keyword and decrypt each character
*** Using its ASCII code + 17 + Random Key + Position in Keyword
FOR lnCnt = 2 TO LEN(lcEnc)
lcChar = SUBSTR(lcEnc, lnCnt, 1)
lcRaw = lcRaw + CHR( ASC(lcChar) - (17 + lnVar + lnCnt) )
NEXT
RETURN lcRaw

沒有留言:

張貼留言