Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encrypting a long string
Message
De
14/02/2019 19:50:19
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01666383
Message ID:
01666396
Vues:
45
J'aime (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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform