Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Encryption function
Message
 
À
26/06/1998 15:08:39
Christian Bellavance
Université du Québec à Hull
Hull, Québec, Canada
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Divers
Thread ID:
00112039
Message ID:
00112064
Vues:
35
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform