Make your own free website on Tripod.com

Encrypt And Decrypt Strings


'This example is useful to encrypt passwords or other secret information.
'you will be able to save the encrypted strings to file and the user will not be able
'to read them even if he will open the file.
'Add 2 CommandButtons to your form (named Command1 and Command2).
'When you will press the first button you will get the encrypted string.
'To decrypt the string press the second button.
'Insert the following code to your form:

Dim Code As String, DataString As String, Temp As String
Sub Translate()
Dim I As Integer
Dim location As Integer
Temp$ = ""
For I% = 1 To Len(DataString$)
location% = (I% Mod Len(Code$)) + 1
Temp$ = Temp$ + Chr$(Asc(Mid$(DataString$, I%, 1)) Xor _
Asc(Mid$(Code$, location%, 1)))
Next I%
End Sub

Private Sub Command1_Click()
'This code is the encryption formula. Replace 'abcdefghijk' with every string you want.
'you can even change the string length.

Code = "abcdefghijk"
'Replace the 'It's the secret message' with the string you want to encrypt.
DataString = "It's the secret message"
Translate
MsgBox (Temp$)
End Sub

Private Sub Command2_Click()
DataString = Temp$
Translate
MsgBox (Temp$)
End Sub

Go Back