Here's an encryption/decryption algorithm (that I made in about 15 min) that it's close to what experts use, I also added comments, hoping that you might understand what's going on...
If you look carefully at the result, you will see that the a's in the encrypted string are all different characters, and that is TRUE encryption, since there are no patterns in the result...
VB Code:
Option Explicit Private Sub Form_Load() Dim EncStr As String EncStr = RndCrypt("String I want to encrypt... aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "pass12") Debug.Print EncStr Debug.Print RndCrypt(EncStr, "pass12") End Sub Public Function RndCrypt(ByVal Str As String, ByVal Password As String) As String Dim SK As Long, K As Long ' init randomizer for password Rnd -1 Randomize Len(Password) ' Chr(((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd)) -> makes sure that a ' password like "pass12" does NOT give the same result as the password "sspa12" or "12pass" ' or "1pass2" etc. (or any combination of the same letters) For K = 1 To Len(Password) Mid$(Password, K, 1) = Chr(((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd)) SK = SK + Asc(Mid$(Password, K, 1)) 'add all aschii values Next K ' init randomizer for encryption/decryption Rnd -1 Randomize SK ' encrypt/decrypt every character using the randomizer For K = 1 To Len(Str) Mid$(Str, K, 1) = Chr(Fix(256 * Rnd) Xor Asc(Mid$(Str, K, 1))) Next K RndCrypt = Str End Function
