String Encrypt and Decrypt
These two function provide a simple method to encrypt and decrypt a string. Simply drop this code in to a module, and it is ready for use.
Option Explicit
Public Function Encrypt(ByVal icText As String) As String
Dim icLen As Integer
Dim icNewText As String
icChar = ""
icLen = Len(icText)
For i = 1 To icLen
icChar = Mid(icText, i, 1)
Select Case Asc(icChar)
Case 65 To 90
icChar = Chr(Asc(icChar) + 127)
Case 97 To 122
icChar = Chr(Asc(icChar) + 121)
Case 48 To 57
icChar = Chr(Asc(icChar) + 196)
Case 32
icChar = Chr(32)
End Select
icNewText = icNewText + icChar
Next
Encrypt = icNewText
End Function
Public Function Decrypt(ByVal icText As String) As String
Dim icLen As Integer
Dim icNewText As String
icChar = ""
icLen = Len(icText)
For i = 1 To icLen
icChar = Mid(icText, i, 1)
Select Case Asc(icChar)
Case 192 To 217
icChar = Chr(Asc(icChar) - 127)
Case 218 To 243
icChar = Chr(Asc(icChar) - 121)
Case 244 To 253
icChar = Chr(Asc(icChar) - 196)
Case 32
icChar = Chr(32)
End Select
icNewText = icNewText + icChar
Next
Decrypt = icNewText
End Function
Special Instructions
This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.