Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encrypting a long string
Message
 
 
À
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:
01666398
Vues:
31
>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
>
This code works every time. Thank you. But (don't take it as a criticism of your approach).
The decripted string looks the same every time the original string is the same. So, as I mentioned in one of the previous messages, the downside is that a user can simply copy a value from one record to another.
It would be nice if the encrypted string would look different even for the same unencrypted string.
I may just have to live with this.
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform