Public Function Encrypt(strString As String) As String
' DESCRIPTION:
' Function takes a character string and encrypts it by
' offsetting each character of the string by an integer value.
'
' In the event that the character string is equal to "OTH000"
' the string is not encrypted.
'
'
' INPUTS:
' strString -String expression to encrypt
'
'
' OUTPUT:
' Encrypt -Encrypted string
'
'
'declare variables
Dim intStrLength As Integer
Dim intOffset As Integer
Dim OffsetOffset As Integer
Dim intCounter As Integer
Dim strLetter As String
Dim intLetterPlain As Integer
Dim intLetterEncrypted As Integer
Dim strLetterEncrypted As String
Dim strEncryptedString As String
'set character offset value
intOffset = 12
OffsetOffset = 300
'calculate length of string to encrypt
intStrLength = Len(strString)
MsgBox "Length = " & intStrLength, vbExclamation, "encrypt"
'test to see if strString is "OTH000"
If strEncryptedString = "OTH000" Then
strString = "OTH000"
Else
'encrypt string one letter at a time
'build encrypted string by concatenating one letter at a time
'stop at end of string
For intCounter = 1 To intStrLength
strLetter = Mid(strString, intCounter, 1)
intLetterPlain = Asc(strLetter) - 32
intLetterEncrypted = intLetterPlain + intOffset + OffsetOffset
OffsetOffset = OffsetOffset + 1
strLetterEncrypted = Chr$(intLetterEncrypted Mod 256)
strEncryptedString = strEncryptedString & strLetterEncrypted
Next intCounter
End If
'return encrypted string
Encrypt = strEncryptedString
End Function
Public Function Decrypt(strEncryptedString As Variant) As String
' DESCRIPTION:
' Function takes a the chatacter string previously encrypted by
' the Encrypt() function, and returns the original plain text
' character string values.
'
' In the event that the character string is equal to "OTH000"
' the string is not decrypted.
'
'
' INPUTS:
' strEncryptedString -Encrypted string expression
'
'
' OUTPUT:
' Decrypt -Decrypted string
'
'
'declare variables
Dim intStrLength As Integer
Dim intOffset As Integer
Dim OffsetOffset As Integer
Dim intCounter As Integer
Dim strLetter As String
Dim intLetterPlain As Variant
Dim strLetterPlain As String
Dim intLetterEncrypted As Integer
Dim strLetterEncrypted As String
Dim strString As String
'set character offset value
intOffset = 12
OffsetOffset = 300
'test to see if strString is null
If IsNull(strEncryptedString) Then
strString = ""
'test to see if strString is "OTH000"
ElseIf strEncryptedString = "OTH000" Then
strString = "OTH000"
Else
'calculate length of string to encrypt
intStrLength = Len(strEncryptedString)
MsgBox "Length = " & intStrLength, vbExclamation, "decrypt"
'encrypt string one letter at a time
'build encrypted string by concatenating one letter at a time
'stop at end of string
For intCounter = 1 To intStrLength
strLetterEncrypted = Mid(strEncryptedString, intCounter, 1)
intLetterEncrypted = Asc(strLetterEncrypted)
intLetterPlain = intLetterEncrypted - intOffset - OffsetOffset
OffsetOffset = OffsetOffset + 1
While intLetterPlain < 0
intLetterPlain = intLetterPlain + 256
Wend
strLetterPlain = Chr$(intLetterPlain + 32)
strString = strString & strLetterPlain
Next intCounter
End If
'return encrypted string
Decrypt = strString
End Function