Added: Nov 21, 2001
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo
Easy String Encryption Using A Password There are many algorithms available for string encryption and decryption, but often they become complicated due to the need to ensure that the ASCII value of an encrypted character stays within the limits of a single byte (0-255). An elegant approach is to use the XOR function. The simple subroutine below will always give results falling within the 0-255 limit. It also has the advantage that a second call will reverse the encryption automatically. One thing you should be aware of is that the encrypted string may contain Chr$(0) values. While this will not be a problem with Visual Basic strings, other Windows objects treat Chr$(0) as an end-of-string character. Use of the encrypted string with a Text Box or in API calls may produce unexpected results.
Highlight all by clicking in box
Function Encrypt(sPassWord As String, sText As String) As String
Dim I As Integer
Dim iPChar As Integer
Dim iCChar As Integer
Do While Len(sPassWord) < Len(sText)
sPassWord = sPassWord & sPassWord
For I = 1 To Len(sText)
iPChar = Asc(Mid$(sPassWord, I, 1))
Char = Asc(Mid$(sText, I, 1))
d$(sText, I, 1) = Chr$(iPChar Xor iCChar)
Encrypt = sText
No Comments to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Adding your comment. Please wait...
Thanks for adding your comment!. After further review it will be added.
There was a problem adding your comment. Please try again.
Please complete all the fields in the form before sending.