Skip to main content

Encrypt and Decrypt a Text using VB6

Last week, we made a program in that has encryption only in a text. Now in this article, we will create a program in VB6.0 that will encrypt and decrypt a text.

Now, let's start this tutorial!

1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open.

2.Next, add two Buttons named Command1 and labeled it as "Encrypt". Add also DTPicker named DTPicker1 and format it dtpShortDate .You must design your interface like this:


3. Now put this code for your code module.

  1. Private Sub Command1_Click()
  2. Text2.Text = Encrypt(Text1.Text, Len(Text1.Text))
  3. End Sub
  5. Public Function Encrypt(Name As String, Key As Long) As String
  6. Dim v As Long, c1 As String, z As String
  7. For v = 1 To Len(Name)
  8. c1 = Asc(Mid(Name, v, 1))
  9. c1 = Chr(c1 + Key)
  10. z = z & c1
  11. Next v
  12. Encrypt = z
  13. End Function
  15. Private Sub Command2_Click()
  16. Text2.Text = Decrypt(Text2.Text, Len(Text1.Text))
  17. Text1.Text = ""
  18. End Sub
  20. Public Function Decrypt(Name As String, Key As Long) As String
  21. Dim v As Long, c1 As String, z As String
  22. For v = 1 To Len(Name)
  23. c1 = Asc(Mid(Name, v, 1))
  24. c1 = Chr(c1 - Key)
  25. z = z & c1
  26. Next v
  27. Decrypt = z
  28. End Function


We have created a function for Encrypt and Decrypt that has the parameters of Name As String and Key As Long. We have initialized v as Long Integer, variable c1 as String, and variable z as String. Then we have created a For Next Loop where v=1 up to the Length of text to our Name variable. Variable c1 now will be equal to Asc Function of Mid text of the name, starts at variable v, and the length of 1. Asc Function returns an Integer representing the character code corresponding to the first letter in a string. The required string argument is any valid string expression. If the string contains no characters, a run-time error occurs. Then c1 = Chr(c1 + Key). This statement is the main syntax for encrypting and decrypting the text. If we put Chr(c1 + Key) it is used for encryption and Chr(c1 - Key) is used for decryption. Chr Function returns a String containing the character associated with the specified character code. The required charcode argument is a Long that identifies a character.

was used for encryption as Text2 will have the value of the encrypt word inputted in Text1 and its length. And Command2/Button2 was used for decryption as Text2 will be decrypted the encrypted text in Text2.




Download the source code and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below and hire me.

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09488225971
E-mail:[email protected]

Follow and add me in my Facebook Account:

Visit and like my page on Facebook at:

Visit my website at:

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Submitted byfleur (not verified)on Sun, 08/03/2014 - 09:52

What is the use of DTPicker?

Submitted bydonbermoyon Thu, 08/07/2014 - 14:07

In reply to by fleur (not verified)

DTPicker is used for viewing time and dates.

Submitted byConcerned citzen (not verified)on Wed, 07/06/2016 - 22:03

This post should have a giant disclaimer that this encryption algorithm should in no possible way be considered secure. It should only be used to obscure a text for personal fun at the most, never for any data that you want to secure. Even if you don't care about the data, in this day and age you should jut download a control that does real encryption.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.