Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encryption of a field in VFP 5
Message
De
23/09/1998 21:03:07
 
 
À
23/09/1998 06:58:52
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00139739
Message ID:
00140164
Vues:
27
>I have a need to encrypt, at table level, a single field of that table, a password login. Could anybody offer a suggestion as to the best way to do this, it would be very much appreciated.
>
>Thank you

You can write your own very fast encrption using the wonderful properties of XOR
Crypt will return the original value when passed the encrypted value and vice versa!

Here's a sample.. (i've changed a few lines to protect my own security so please test it :-)
*!***********************************************
*!
*!      Procedure: CRYPT
*!
*!***********************************************
PROCEDURE Crypt
LPARAMETERS cStr, cKey
LOCAL ii, nLen, p1, p2, cStr1, cKey2, cOut, n1, n2, n3
* cKey, if used for tight security, should be a word with a prime number of characters, e.g. "implemented"
l1= LEN(m.cKey)
cKey2= "abcdefghijklmnopqrstuvwxyzABC"  && internal key, length 29
cStr1= TRIM(m.cStr)
nLen= LEN(m.cStr1)
cOut= ""
p1= m.l1 % m.nLen + 1		&& pointer 1
p2= 29 % m.nLen + 1		&& pointer 2
FOR m.ii = m.nLen TO 1 STEP -1
	n1= ASC(SUBSTR(m.cStr1, m.ii, 1))
	n2= ASC(SUBSTR(m.cKey, m.p1, 1))
	n3= ASC(SUBSTR(m.cKey2, m.p2, 1))
	cOut= CHR(BITXOR(BITXOR(m.n1, m.n2), m.n3)) + m.cOut
	* increment the counters
	p1= m.p1 + 1
	IF m.p1 > m.l1
		p1= 1
	ENDIF
	p2= m.p2 + 1
	IF m.p2 > 29
		p2= 1
	ENDIF
ENDFOR
RETURN m.cOut
HTH
Dave
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform