This is a test of a rudimentary encryption/decryption
algorithm.
Note: It is possible for the encrypted string to include Chr$(0).
Visual Basic handles this just fine but Windows (and
therefore the TextBox control) uses Chr$(0) to signify the end
of the string. Therefore, programs such as this one that store
the encrypted data in a text box may end up truncating the data.
The following Visual Basic project contains the source code and Visual Basic examples used for encrypt/decrypt string. Besides providing these functions in a ready to use.bas module, he has also wrapped them in a DLL. Download Source Code. Download the source code and press F5 to run the program. Enter a string then press the Encrypt / Decrypt button. About TheScarms. Vb6 Software - Free Download Vb6 - Top 4 Download - Top4Download.com offers free. software downloads for Windows, Mac, iOS and Android computers and mobile devices. Visit for free, full and secured.



First, add a textbox, called txtText, with its MultiLine property set to true. Then, add another textbox called txtPassword, and two command buttons named cmdEncrypt, and cmdDecrypt. Finally, add the code below.
'This program may be distributed on the condition that it is
'distributed in full and unchanged, and that no fee is charged for
'such distribution with the exception of reasonable shipping and media
'charged. In addition, the code in this program may be incorporated
'into your own programs and the resulting programs may be distributed
'without payment of royalties.
'
'This example program was provided by:
' SoftCircuits Programming
' http://www.softcircuits.com
' P.O. Box 16262
' Irvine, CA 92623
Option Explicit
'Set to True to make the password case-sensitive
#Const CASE_SENSITIVE_PASSWORD = False
Private Sub cmdEncrypt_Click()
' You can encrypt twice for extra security
txtText = EncryptText((txtText), txtPassword)
txtText = EncryptText((txtText), txtPassword)
End Sub
Private Sub cmdDecrypt_Click()
txtText = DecryptText((txtText), txtPassword)
txtText = DecryptText((txtText), txtPassword)
End Sub
'Encrypt text
Private Function EncryptText(strText As String, ByVal strPwd As String)
Dim i As Integer, c As Integer
Dim strBuff As String
#If Not CASE_SENSITIVE_PASSWORD Then
'Convert password to upper case
'if not case-sensitive
strPwd = UCase$(strPwd)
#End If
'Encrypt string
If Len(strPwd) Then
For i = 1 To Len(strText)
c = Asc(Mid$(strText, i, 1))
c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr$(c And &HFF)
Next i
Else
strBuff = strText
End If
EncryptText = strBuff
End Function
'Decrypt text encrypted with EncryptText
Private Function DecryptText(strText As String, ByVal strPwd As String)
Dim i As Integer, c As Integer
Dim strBuff As String
#If Not CASE_SENSITIVE_PASSWORD Then
'Convert password to upper case
'if not case-sensitive
strPwd = UCase$(strPwd)
#End If
'Decrypt string
If Len(strPwd) Then
For i = 1 To Len(strText)
c = Asc(Mid$(strText, i, 1))
c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr$(c And &HFF)
Next i
Else
strBuff = strText
End If
DecryptText = strBuff
End Function


| Procedure Name | Type | Description |
| (Declarations) | Declarations | Declarations and private variables for the CEncryption class. |
| InputFileName | Property | Get the name of the input file. |
| OutputFileName | Property | Get the name of the output file. |
| Password | Property | Get the password. |
| Class_Initialize | Initialize | Set initial values to defaults which may be overridden with property settings. |
| EncryptFile | Method | Encrypt the file specified in m_strInputFileName to the file specified in m_strOutputFileName. This procedure uses buffered file reads and writes for better performance. The encrypted file produced by the method is reversible. This means that if you encrypt a file, reverse the InputFileName and OutputFileName properties, and call this method again, the original file is restored. Note: The same password must be supplied to successfully decrypt the file. This method also raises an event called file progress. This event can be used to track the progress of the file being processed. See the example tab for an example of how to use this event. This method also uses a file buffer. Using a file buffer significantly speeds up the performance of this method. |
| EncryptString | Method | Encrypt/Decrypt the passed string with XOR encryption. The encrypted string produced by the method is reversible. This means that if you encrypt a string, then encrypt the results of that operation, the original string is restored. Note: The same password must be supplied to successfully decrypt the string. See the example tab for a demonstration of this. If you need an ASCII version of this function, use the EncryptStringAscii method. |
| EncryptStringAscii | Method | Encrypt/Decrypt the passed string with XOR encryption, returning the result in ASCII format. The encrypted string produced by the method is reversible. This means that if you encrypt a string, then encrypt the results of that operation, the original string is restored. Note: The same password must be supplied to successfully decrypt the string. See the example tab for a demonstration of this. The EncryptStringAscii method returns the result in ASCII format. If you need to pass the results of the EncryptString function on the command line, or use it external to your program, it is recommended that you use the ASCII version of this function. |
| EncryptByte | Private | Encrypt one byte, and modify the password. Modifying the password as we encrypt makes the encryption slightly harder to break. |
| ReadFile | Private | Read the specified number of bytes from the file. This function significantly increases the speed of processing files. The alternative to using a file buffer is reading a byte at a time from the file. |