by S Rajkumar (2 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 5th February 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
How to Decode a string
Form1.Show ' Must Show form in Load event before Print is visible.
secret$ = "This is the string that will be encrypted."
PassWord$ = "password"
Call Encrypt(secret$, PassWord$) 'Encrypt the string.
Print " After encrypting it once: " 'Print the result.
Print secret$
Print
Call Encrypt(secret$, PassWord$) 'A second call to the Encrypt
Print "After a second encryption:" 'subroutine now decrypts the
Print secret$ 'encrypted string.
End Sub
Sub Encrypt(secret$, PassWord$)
' secret$ = the string you wish to encrypt or decrypt.
' PassWord$ = the password with which to encrypt the string.
L = Len(PassWord$)
For X = 1 To Len(secret$)
Char = Asc(Mid$(PassWord$, (X Mod L) - L * ((X Mod L) = 0), 1))
Mid$(secret$, X, 1) = Chr$(Asc(Mid$(secret$, X, 1)) Xor Char)
Next
End Sub