Hi,

Who can anyone give me the simplest method for encryption and decryption for text file? I saw a lot of methods in other website. So, I choose the simplest one, but it gives me some errors when I do it. This is the reference link.
http://www.vb6.us/tutorials/basic-encryption-xor-tutorial

Dim strResult As String
Dim strChar1 As String * 1

Private Sub Command1_Click()
    Dim Str_Lenght As Integer
    Dim Ori_text As String, Deci As String, Deci2 As String
    
    Ori_text = Text1.Text
    Str_Lenght = Len(Ori_text)
    
    strResult = ""
    
    If (Str_Lenght <> 0) Then
        For i = 1 To Str_Lenght
            Deci = Deci & Asc(Mid(Ori_text, i, 1)) & ", "
            strResult = strResult & Chr(Asc(Mid(Ori_text, i, 1)) Xor Asc(strChar1))
            Deci2 = Deci2 & Asc(Chr(Asc(Mid(Ori_text, i, 1)) Xor Asc(strChar1))) & ", "
        Next i
    Else
        strResult = "No data!"
    End If
    
    Text2.Text = strResult
    Label5.Caption = Deci
    Label7.Caption = Deci2
End Sub

Private Sub Command2_Click()
    Dim Str_Lenght As Integer
    Dim Ori_text As String, Deci As String, Deci2 As String
    
    Ori_text = Trim(Text2.Text)
    Str_Lenght = Len(Ori_text)
    
    strResult = ""
    
    If (Str_Lenght <> 0) Then
        For i = 1 To Str_Lenght
            Deci2 = Deci2 & Asc(Mid(Ori_text, i, 1)) & ", "
            strResult = strResult & Chr(Asc(Mid(Ori_text, i, 1)) Xor Asc(strChar1))
            Deci = Deci & Asc(Chr(Asc(Mid(Ori_text, i, 1)) Xor Asc(strChar1))) & ", "
        Next i
    Else
        strResult = "No data!"
    End If
    
    Text3.Text = strResult
    Label4.Caption = Deci
    Label6.Caption = Deci2
End Sub

Private Sub Form_Load()
    strChar1 = "z"
    Command1.Caption = "Encryption"
    Command2.Caption = "Decryption"
End Sub

If you see the attached file, all of you will see the error.

Pls give me som suggestion.

Regards,
zawpai

you can try this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.