Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 5
Viewed: 3012
Added: Nov 21, 2001
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

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
<!---Declaration--->
none

Highlight All
<!---Code--->
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

Loop

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)

Next I

Encrypt = sText

End Function;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


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.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions