I'm creating my own encryption-of-sorts on my application. The application is VERY simplistic so I don't need any hugely complicated encryption.
Basically,
I want my program to automatically convert characters in a string. I already know the conversion method that I'm going to use I just need help with the syntax.
So, in plain english, what i need is code that will
For each letter in STRING.
Replace A with B (case statement?)
Until the end of the string.
Here's a basic example. Say I want to use the following encryption (we'll just use numbers for now, since there's only 10 of them).
User enters "1234567890" into a textbox and presses encrypt.
My application goes through the string, one character at a time and checks for the 'switching' rule. In this example i'll use
1 becomes 2
2 becomes 3
...etc...
9 becomes 0
0 becomes 1
So, in textbox two the "encrypted" string would be: 234567890
Can someone help me with code on this please? I"m a newbie and I think my theory works for what I want to do, just not sure the most efficient way to do this.
I've created a conversion chart for all possible character entries. So, to answer your question... I'm going to be converting both/everything.... all letters, numbers, special characters.
I already know what conversions I'm going to use... just need to know how to do it.
Because I've got conversions for every possible character, this should be a simple "for each character, if it's THIS, make it THAT, move to the next character, until there are no more characters". And i'll use the reverse for my decryption.
Edited: I put some code together too. You just need to use the same string key to encrypt and decrypt the string. Make the key at least with six chars including letters and numbers for more security. It is simple and very hard to break.
VB Code:
Public Function Encrypt(ByVal _string As String, ByVal key As String) As String
Dim encryptString As String = ""
Dim i, i1, ascii As Integer
If _string <> "" AndAlso key <> "" Then
i1 = key.Length - 1
For Each ch As Char In _string
While i <= i1
ascii = AscW(ch) Xor AscW(key.Substring(i))
ch = ChrW(ascii)
i += 1
End While
i = 0
i1 -= 1
If i1 < 0 Then
i1 = key.Length - 1
End If
encryptString &= ChrW(ascii)
Next
End If
Return encryptString
End Function
Public Function Decrypt(ByVal _string As String, ByVal key As String) As String
Dim decryptString As String = ""
Dim i, i1, ascii As Integer
If _string <> "" AndAlso key <> "" Then
For Each ch As Char In _string
i = key.Length - 1
While i - i1 >= 0
ascii = AscW(ch) Xor AscW(key.Substring(i - i1))
ch = ChrW(ascii)
i -= 1
End While
i1 += 1
If i1 > key.Length - 1 Then
i1 = 0
End If
decryptString &= ChrW(ascii)
Next
End If
Return decryptString
End Function
Last edited by VBDT; Oct 5th, 2006 at 07:51 AM.
Rating is a way of saying thank you. Don't forget to rate always!