Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Encryption function
Message
 
To
26/06/1998 15:08:39
Christian Bellavance
Université du Québec à Hull
Hull, Quebec, Canada
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00112039
Message ID:
00112064
Views:
36
>Does someone have an example of a function that can encrypt and de-encrypt values. Not something to complicated but i a little function that can do the job.
>
>Thanks.

Voici deux petites fonctions que j'utilise régulièrement:

' *****************************************************************
' ***
' *** Decrypte le mot de passe
' ***
' *****************************************************************
Public Function DecryptPassword(ByVal pNumber As Byte, ByVal pEncryptedPassword As String) As String
Dim intChar As Integer
Dim lngX As Long
Dim strPassword As String

lngX = 1
Do Until lngX = Len(Trim$(pEncryptedPassword)) + 1
intChar = Asc(Mid$(pEncryptedPassword, lngX, 1)) Xor (10 - pNumber)
If lngX Mod 2 = 0 Then
intChar = intChar + pNumber
Else
intChar = intChar - pNumber
End If
strPassword = strPassword & Chr$(intChar)
lngX = lngX + 1
Loop

DecryptPassword = strPassword
End Function

' *****************************************************************
' ***
' *** Encrypte le mot de passe
' ***
' *****************************************************************
Public Function EncryptPassword(ByVal pNumber As Byte, ByVal pDecryptedPassword As String) As String
Dim intChar As Integer
Dim lngX As Long
Dim strPassword As String

lngX = 1
Do Until lngX = Len(pDecryptedPassword) + 1
intChar = Asc(Mid$(pDecryptedPassword, lngX, 1))
If lngX Mod 2 = 0 Then
intChar = intChar - pNumber
Else
intChar = intChar + pNumber
End If
intChar = intChar Xor (10 - pNumber)
strPassword = strPassword & Chr$(intChar)
lngX = lngX + 1
Loop

EncryptPassword = strPassword
End Function

Le paramètre pNumber est un chiffre que tu passe pour changer l'offset de ton encryption. Comme ca, même si quelqu'un connait la fonction pour décrypter mais qu'il ne connait pas l'offset, il ne pourra pas le décoder du premier coup!!!
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform