Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Encrypting a long string
Message
From
14/02/2019 19:50:19
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01666383
Message ID:
01666396
Views:
44
Likes (1)
The other version still doesn't seem to always work. I switched it to use the C Standard Library's RAND() and SRAND() functions:
CLEAR
lcEnc = encrypt("Test string here")
? lcEnc
lcDec = decrypt(lcEnc)
? lcDec



FUNCTION encrypt
LPARAMETERS tcString
LOCAL lcString

    seedRand(0)
    lcString = SPACE(0)
    FOR lnI = 1 TO LEN(tcString)
        lnRand      = ROUND(getRand() * 255.0, 0)
        lcChar      = SUBSTR(tcString, lnI, 1)
        lcChar      = CHR((ASC(lcChar) + lnRand) % 255)
        lcString    = lcString + lcChar
    NEXT
    RETURN lcString




FUNCTION decrypt
LPARAMETERS tcString
LOCAL lcString

    seedRand(0)
    lcString = SPACE(0)
    FOR lnI = 1 TO LEN(tcString)
        lnRand      = ROUND(getRand() * 255.0, 0)
        lcChar      = SUBSTR(tcString, lnI, 1)
        lcString    = lcString + CHR((ASC(lcChar) + 255 - lnRand) % 255)
    NEXT
    RETURN lcString




FUNCTION seedRand
LPARAMETERS tnSeed

    DECLARE INTEGER srand IN msvcr71.dll as cSrand INTEGER nSeed
    DECLARE INTEGER rand  IN msvcr71.dll AS cRand
    cSrand(tnSeed)




FUNCTION getRand
LOCAL lnRand

    RETURN cRand() / 32767.0
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform