Tuesday, January 20, 2009

Simple String Encryption

Public Function EncryptString(ByVal InSeed As Integer, ByVal InString As String) As String
   Dim c1 As Integer
   Dim NewEncryptString As String
   Dim EncryptSeed As Integer
   Dim EncryptChar As String

   NewEncryptString = ""
   EncryptSeed = InSeed
   For c1 = 1 To Len(InString)
      EncryptChar = Mid(InString, c1, 1)
      EncryptChar = Chr(Asc(EncryptChar) Xor EncryptSeed)
      EncryptSeed = EncryptSeed Xor c1
      NewEncryptString = NewEncryptString & EncryptChar
   Next

   EncryptString = NewEncryptString
End Function

Passing in a seed and your string will return an encrypted string. Pass in the same seed and the encrypted string again and it will return the original unencrypted string.

No comments: