Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encrypting tool
Message
De
26/10/2004 15:09:39
 
 
À
26/10/2004 15:08:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000
Network:
Windows 2000 Pro
Database:
Visual FoxPro
Divers
Thread ID:
00954646
Message ID:
00954649
Vues:
20
Thank you.


>>We want to "protect" our password that is stored in our user table.
>>Is there an encryting tool built in VFP8.0 that I can use?
>
>This is custom but if you can't find something built in, it might help:
>
>
>* Text encryption
>* expC1 Text to encrypt
>* expC2 Encryption key (without this key, the text will not be encrypt)
>* Return the encrypted text
>* The lenght of the returned string equal the lenght of the text to encrypt
>FUNCTION Encrypt
>LPARAMETERS tcTxt,tcKey
>LOCAL lnPKey,lnLenKey,lnLenTxt,lcKey,lcRes,lnNPos,lnByte,lnAscKey,;
> lnSumAsc,lnPosIgnore,lnKeySXOR,lnKeyLXOR,lnKeyBXOR,lcKey
>
>STORE IIF(EMPTY(M.tcKey),"CLEF D'ENCRYPTAGE",tcKey) TO lcKey
>STORE LEN(lcKey)                                      TO lnLenKey
>STORE LEN(tcTxt)                                      TO lnLenTxt
>
>LOCAL ARRAY laSKey[lnLenTxt,2]
>
>STORE 0 TO lnSumAsc, lnKeyBXOR
>FOR lnPKey = 1 TO lnLenKey
>   STORE lnSumAsc + ASC(SUBSTR(lcKey, lnPKey, 1))  TO lnSumAsc
>NEXT
>
>FOR lnPKey = 1 TO lnLenTxt
>   STORE SUBSTR(lcKey, (lnPKey % lnLenKey)+1, 1)                     TO laSKey[lnPKey,1]
>   STORE ASC(laSKey[lnPKey,1])                                           TO lnAscKey
>   STORE BITXOR(lnKeyBXOR,BITAND(255,BITLSHIFT(lnAscKey, lnPKey%5))) TO lnKeyBXOR
>   STORE lnPKey                                                          TO laSKey[lnPKey,2]
>NEXT
>
>STORE lnSumAsc % 3                           TO lnPosIgnore
>STORE BITRSHIFT(lnSumAsc,lnLenKey%3) % 256 TO lnKeySXOR
>STORE lnLenKey % 256                         TO lnKeyLXOR
>
>=ASORT(laSKey)
>
>STORE "" TO lcRes
>FOR lnPos = 1 TO lnLenTxt
>   STORE laSKey[lnPos,2]                            TO lnNPos
>   STORE ASC(SUBSTR(tcTxt,lnNPos,1))              TO lnByte
>   STORE BITXOR(lnByte, 2^(1+lnPos%4))            TO lnByte
>   STORE BITXOR(lnByte, 2^(1+lnNPos%4+lnPos%2)) TO lnByte
>   STORE BITXOR(lnByte, lnKeySXOR)                TO lnByte
>   STORE BITXOR(lnByte, lnKeyLXOR)                TO lnByte
>   STORE BITXOR(lnByte, lnKeyBXOR)                TO lnByte
>   STORE BITXOR(lnByte, ASC(laSKey[lnPos,1]))     TO lnByte
>
>   STORE lcRes + CHR(lnByte)                      TO lcRes
>NEXT
>RETURN lcRes
>
>
>* Text decryption
>* expC1 Text to decrypt
>* expC2 Encryption key (without this key, the text will not be decrypt)
>* Return the decrypted text
>* The lenght of the returned string equal the lenght of the text to decrypt
>FUNCTION Uncrypt
>LPARAMETERS tcTxt,tcKey
>LOCAL lnPKey,lnLenKey,lnLenTxt,lcKey,lcRes,lnNPos,lnByte,lnAscKey,;
> lnSumAsc,lnPosIgnore,lnKeySXOR,lnKeyLXOR,lnKeyBXOR,lcKey
>
>STORE IIF(EMPTY(tcKey), "CLEF D'ENCRYPTAGE", tcKey) TO lcKey
>STORE LEN(lcKey) TO lnLenKey
>STORE LEN(tcTxt) TO lnLenTxt
>
>LOCAL ARRAY laSKey[lnLenTxt,2]
>
>STORE 0 TO lnSumAsc, lnKeyBXOR
>FOR lnPKey = 1 TO lnLenKey
>   STORE lnSumAsc + ASC(SUBSTR(lcKey, lnPKey, 1))  TO lnSumAsc
>NEXT
>FOR lnPKey = 1 TO lnLenTxt
>   STORE SUBSTR(lcKey, (lnPKey % lnLenKey)+1, 1)                     TO laSKey[lnPKey,1]
>   STORE ASC(laSKey[lnPKey,1])                                           TO lnAscKey
>   STORE BITXOR(lnKeyBXOR,BITAND(255,BITLSHIFT(lnAscKey, lnPKey%5))) TO lnKeyBXOR
>   STORE lnPKey                                                          TO laSKey[lnPKey,2]
>NEXT
>
>STORE lnSumAsc % 3                           TO lnPosIgnore
>STORE BITRSHIFT(lnSumAsc,lnLenKey%3) % 256 TO lnKeySXOR
>STORE lnLenKey % 256                         TO lnKeyLXOR
>
>=ASORT(laSKey)
>
>STORE SPACE(lnLenTxt) TO lcRes
>FOR lnPos = 1 TO lnLenTxt
>   STORE laSKey[lnPos,2]                            TO lnNPos
>   STORE ASC(SUBSTR(tcTxt,lnPos,1))               TO lnByte
>   STORE BITXOR(lnByte, ASC(laSKey[M.lnPos,1]))     TO lnByte
>   STORE BITXOR(lnByte, lnKeyBXOR)                TO lnByte
>   STORE BITXOR(lnByte, lnKeyLXOR)                TO lnByte
>   STORE BITXOR(lnByte, lnKeySXOR)                TO lnByte
>   STORE BITXOR(lnByte, 2^(1+lnNPos%4+lnPos%2)) TO lnByte
>   STORE BITXOR(lnByte, 2^(1+lnPos%4))            TO lnByte
>   STORE STUFF(lcRes, lnNPos, 1, CHR(lnByte))   TO lcRes
>NEXT
>RETURN lcRes
>
Work as if you don't need money
Love as if you've never been hurt before
Live as if this is your last day to live
Dance as if no one's watching
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform