Anyone have a good simple encryption/decrpytion function?
to encrypt/decrypt a string?
nothing fancy, just one that will work 100% and return characters that can be seen in a textbox.. (there are some functions that return really high ascii characters that are 'boxes' in textboxes... and if one was to copy that to a text file, then decrypt the data in the text file, the boxes would all decrpyt to a single character, since they all have the same ascii code)
Re: Anyone have a good simple encryption/decrpytion function?
Do a search of the forums. There are many examples as the subject comes up every week. You can also search in the CodeBank, for complete solutions.
If you want simple encryption, you could just loop through the textbox character by character. For each character, take the x=ASC() number of the key, and add a nother number to it (say 2). Then change the character to z=chr(x+2)
This would change David into Fcxkf. Then to decrypt, just reverse the process to get David.
VB Code:
' Encrypt
dim a%,x%,z$
for a=1 to len(text1.text)
x=asc(mid(text1.text,a,1))
z=chr(x+2)
mid(text1,a,1)=chr(z)
next a
' Decrypt
dim a%,x%,z$
for a=1 to len(text1.text)
x=asc(mid(text1.text,a,1))
z=chr(x-2)
mid(text1,a,1)=chr(z)
next a
Re: Anyone have a good simple encryption/decrpytion function?
Here is one I built yesterday when I was doing nothing.
Thought it's simple, it's hard to crack without knowing the key.
VB Code:
Function Encrypt(sText As String, sKey As String) As String
Dim x As Long, i As Long, k As Long
While i < Len(sText)
Randomize ''Just inserts random chars so that it is hard to decrypt
If Rnd * 10 > 5 And Len(Encrypt) < Len(sText) * 2 Then ''50% chances and limit output length
x = Rnd * 20
Else
i = i + 1
x = Asc(Mid(sText, i, 1))
End If
k = k + 1
Encrypt = Encrypt & Chr(x Xor Asc(Mid(sKey, k, 1)))
If k >= Len(sKey) Then k = 1
Wend
End Function
Function Decrypt(sText As String, sKey As String) As String
Dim x As Long, i As Long, k As Long
For i = 1 To Len(sText)
k = k + 1
x = Asc(Mid(sText, i, 1)) Xor Asc(Mid(sKey, k, 1))
If x > 20 Then Decrypt = Decrypt & Chr(x) ''bcoz we know upto 20 is fake chars
If k >= Len(sKey) Then k = 1
Next
End Function
Pradeep :)
Re: Anyone have a good simple encryption/decrpytion function?
Check out google.
Look for BlowFish, or something like that.
There's VB example source codes for it, and the encryption is pretty strong.
1 Attachment(s)
Re: Anyone have a good simple encryption/decrpytion function?
Here's an example of MD5 encryption.
This class also does other encryption like URL Encoding this MD5 encrypted data, which is handy.
I use this is what I use in my apps. just run Data Encryption.vpg
There is also another demo in this zip that allows you to encypt file.
Woka