ID: 6
Viewed: 3664
Added: Nov 21, 2001
Version:
Snippet uploaded by: snippet
Written By: Clint LaFever
Demo: Sorry, no demo
Thank you for your vote. Please wait...
It appears you already voted for this snippet
It appears your vote value was empty
Encrypts or Decrypts a given string with a given password.
Highlight all by clicking in box
<!---Declaration--->
'------------------------------------------------------------
' Author: Clint LaFever [lafeverc@usa.net]
' Purpose: Encryption Class to Encrypt/Decrypt Strings.
' Parameters: ' Example: ' Date: July,21 1998 @ 18:13:33
'------------------------------------------------------------
Option Explicit
Private mstrPASS As String
Private mstrTEXT As String
Public Property Get Password() As String
Password = mstrPASS End Property
Public Property Let Password(pstr As String)
mstrPASS = pstr
End Property
Public Property Get TextString() As String
TextString = mstrTEXT
End Property
Public Property Let TextString(pstr As String)
mstrTEXT = pstr
End Property
'------------------------------------------------------------
' Author: Clint LaFever [lafeverc@usa.net]
' Purpose: Encrypts a string with a given password.
' Parameters: ' Example:
'------------------------------------------------------------
Public Function EncryptText(Optional strText As String = "", Optional ByVal strPwd As String = "")
Dim i As Integer, c As Integer
Dim strBuff As String
If strText = "" Then strText = Me.TextString
If strPwd = "" Then strPwd = Me.Password
If strPwd <> "" And strText <> "" Then
strPwd = UCase$(strPwd)
If Len(strPwd) Then
For i = 1 To Len(strText)
c = Asc(Mid$(strText, i, 1))
c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr$(c And &HFF)
Next i
Else
strBuff = strText
End If
Me.TextString = strBuff
EncryptText = strBuff
Else
EncryptText = ""
End If
End Function
'------------------------------------------------------------
' Author: Clint LaFever [lafeverc@usa.net]
' Purpose: Decrypts a string with a given password.
' Parameters: ' Example:
'------------------------------------------------------------
Public Function DecryptText(Optional strText As String = "", Optional ByVal strPwd As String = "")
Dim i As Integer, c As Integer
Dim strBuff As String
If strText = "" Then strText = Me.TextString
If strPwd = "" Then strPwd = Me.Password
If strPwd <> "" And strText <> "" Then
strPwd = UCase$(strPwd)
If Len(strPwd) Then
For i = 1 To Len(strText)
c = Asc(Mid$(strText, i, 1))
c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr$(c And &HFF)
Next i
Else
strBuff = strText
End If
Me.TextString = strBuff
DecryptText = strBuff
Else
DecryptText = ""
End If
End Function
Highlight All
<!---Code--->
none;
No Comments to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Adding your comment. Please wait...
Thanks for adding your comment!. After further review it will be added.
There was a problem adding your comment. Please try again.
Please complete all the fields in the form before sending.