Saturday, June 26, 2010

Encryption and Decryption Logic

// Encryption

Public Function Encryption(ByVal str As String) As String
Dim str1 As String
Dim ch As Char
str1 = Nothing
Dim key, code As Integer
key = 100
For i = 0 To str.Length - 1
ch = str(i)
code = (Asc(ch) + key)
If code >= 0 And code <= 255 Then
code = code + 32
str1 = str1 + ChrW(code)
End If
code = 0
Next i
Return str1
End Function


//Decryption


Public Function Decryption(ByVal str As String) As String
Dim str1 As String
Dim ch As Char
str1 = Nothing
Dim key, code As Integer
key = 100

For i = 0 To str.Length - 1
ch = str(i)
code = (Asc(ch) - key)
If code >= 0 And code <= 255 Then
code = code - 32
str1 = str1 + ChrW(code)
End If
Next i
Return str1
End Function

No comments:

Post a Comment