I create a project encrypt and decrypt data in vb.net
how to use this code as a function please help it is work only on a textbox
i want to send a string value then return encrypt value and when i send encrypt value then send me decrypt value.

Click Here

What I have tried:

Private arLetterChars() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 "
Private arEncryptedChars() As Char = "******************************************************"

' encrypt.

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button4.Click
       With TextBox1
           For Each myTextBoxChar As Char In .Text '// loop thru TextBox, one char. at a time.
               For i As Integer = 0 To arLetterChars.Length - 1 '// loop thru all letters in the Array.
                   '// if TextBox char ='s the char in your Array, replace the TextBox char with the same #'ed Array char of the Encrypted letters.
                   If myTextBoxChar = arLetterChars(i) Then .Text = .Text.Replace(myTextBoxChar, arEncryptedChars(i))
               Next
           Next
       End With
   End Sub

'decrypt.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    With TextBox1
        For Each myTextBoxChar As Char In .Text '// loop thru TextBox, one char. at a time.
            For i As Integer = 0 To arEncryptedChars.Length - 1 '// loop thru all Encrypted char.s in the Array.
                '// if TextBox char ='s the char in your Array, replace the TextBox char with the same #'ed Array char of the Letters.
                If myTextBoxChar = arEncryptedChars(i) Then .Text = .Text.Replace(myTextBoxChar, arLetterChars(i))
            Next
        Next
    End With
End Sub

To me this looks like all content (if your code worked) would end up as all asterisks.
Private arEncryptedChars() As Char = "**" (all asterisks)

What was wrong with the example from your link?
Private arEncryptedChars() As Char = "¿s¢çc‹i˜Ö´åÄÚKÍìæ¯~4Ûÿ5ÑûÏÉí³èô§ŠÀÙ9ÒÓ?þ.äƒ%*š¾†±HI2@æŒ,"

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.