1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Public Function Crypt(ByVal strChaine As String, blnCryptage As Boolean) As String
'Utilisation:
'- Cryptage --> Crypt("Chaine a crypter", true)
'- Decryptage -->Crypt("Chaine a decrypter", false)
Dim I As Integer, J As Integer, K As Integer
Dim strCryptKey As String, strLettre As String, strKeyLettre As String
Dim intLettre As Long, intKeyLettre As Long, strResultat As String
If strChaine = "" Then
Crypt = ""
Exit Function
End If
strCryptKey = "Clé secondaire de cryptage"
For K = 0 To 10 Step 1
strResultat = ""
For I = 1 To Len(strChaine) Step 1
strLettre = Mid(strChaine, I, 1)
J = I
Do While J > Len(strCryptKey)
J = J - Len(strCryptKey)
Loop
strKeyLettre = Mid(strCryptKey, J, 1)
intLettre = Asc(strLettre)
intKeyLettre = Asc(strKeyLettre)
If blnCryptage = True Then
intLettre = intLettre + (intKeyLettre * Len(strChaine))
Else
intLettre = intLettre - (intKeyLettre * Len(strChaine))
End If
Do While intLettre > 255
intLettre = intLettre - 255
Loop
Do While intLettre < 0
intLettre = intLettre + 255
Loop
strResultat = strResultat & Chr(intLettre)
Next I
strChaine = strResultat
Next K
Crypt = strResultat
End Function |
Partager