home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 3_2004-2005.ISO / Data / Zips / Enigma_X18288312132004.psc / Source / Encrpytion.bas < prev    next >
BASIC Source File  |  2004-12-13  |  1KB  |  41 lines

  1. Attribute VB_Name = "Encrpytion"
  2. Option Explicit
  3.  
  4. 'This is the Encrypt function (pretty basic but does the job)
  5. Public Function Encrypt(StringToEncrypt As String) As String
  6.     On Error GoTo ErrorHandler
  7.     Dim Char As String, i
  8.     Encrypt = ""
  9.     
  10.     For i = 1 To Len(StringToEncrypt)
  11.         Char = Asc(Mid(StringToEncrypt, i, 1))
  12.         Encrypt = Encrypt & Len(Char) & Char
  13.     Next i
  14.  
  15.     Exit Function
  16. ErrorHandler:
  17.     Encrypt = "Error encrypting string"
  18. End Function
  19.  
  20. 'This is the Decrypt function (pretty basic but does the job)
  21. Public Function Decrypt(StringToDecrypt As String) As String
  22.     On Error GoTo ErrorHandler
  23.     Dim CharCode As String
  24.     Dim CharPos As Integer
  25.     Dim Char As String
  26.     
  27.     Decrypt = ""
  28.     
  29.     Do
  30.         CharPos = VBA.Left(StringToDecrypt, 1)
  31.         StringToDecrypt = Mid(StringToDecrypt, 2)
  32.         CharCode = VBA.Left(StringToDecrypt, CharPos)
  33.         StringToDecrypt = Mid(StringToDecrypt, Len(CharCode) + 1)
  34.         Decrypt = Decrypt & Chr(CharCode)
  35.         
  36.     Loop Until StringToDecrypt = ""
  37.     Exit Function
  38. ErrorHandler:
  39.     Decrypt = "Error decrypting string"
  40. End Function
  41.