Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.

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
Posted
Updated 19-Dec-22 11:56am
v2

You do realize that won't work?
There are a couple of reasons:
1) If the code is exactly as you show, then the output of the encryption method will be all '*' characters - and you cannot under any circumstances decrypt that to get the original input.
2) If you have replaces the characters you change them to to '*' so we can't "break" your encryption, then 1) goes away - but it still won't work. Suppose I type "abc" in the text box, and you change 'a' to 'c', 'b' to 'd', and 'c' to 'e'? You will replace my 'a' with a 'c':
abc ==> cbc
my 'b' with a 'd'
cbc ==> cdc
and my 'c' with an 'e':
cdc ==> ede

When you decrypt that, you can't tell that the 'e's should be different characters...

And besides, this isn't good encryption - it's a basic substitution cypher, and they print magazines full of those every month so little old ladies can do them in their spare time...

Encryption shouldn't work on characters, it should work on bytes - and it should use a key-based algorithm instead of a fixed substitution! :laugh:
 
Share this answer
 
Comments
Jayanta Modak 3-Nov-18 3:01am    
thanks sir for replying
Actually I used some spacial characters in this place of "*" and same quantity of original characters. I not post here please help me sir please ....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900