Effective Encryption Algorithm
Posted: 2002-06-01
By: ArchiveBot
Viewed: 71
Filed Under:
No attachments for this post
Encrypts and decrypts strings
Original Author: Micah Ellett
Inputs
Simply:
DMEncrypt "Text"
and
DMDecrypt "Text"
Assumptions
Pretty straightforward
Returns
2 functions return a string value, either encrypted or decrypted text.
Side Effects
None that I know of
Code
'THIS FUNCTION ENCRYPTS THE INPUT
Public Function DMEncrypt(strText As String)
On Error GoTo Xit
Dim Combine As String, i As Integer, Temp As String
Combine = ""
Temp = ""
For i = 1 To Len(strText) - 1 Step 2
If Len(Trim(Str(Asc(Mid(strText, i, 1))))) < 3 Then
Temp = "0" & Trim(Str(Asc(Mid(strText, i, 1))))
Else
Temp = Trim(Str(Asc(Mid(strText, i, 1))))
End If
Combine = Combine & Temp
If Len(Trim(Str(Asc(Mid(strText, i + 1, 1))))) < 3 Then
Temp = "0" & Trim(Str(Asc(Mid(strText, i + 1, 1))))
Else
Temp = Trim(Str(Asc(Mid(strText, i + 1, 1))))
End If
Combine = Combine & Temp
Next i
Temp = ""
For i = 1 To Len(Combine)
Temp = Temp & Chr(Asc(Mid(Combine, i, 1)) + 128)
Next i
DMEncrypt = Temp
Clipboard.SetText Temp
Exit Function
Xit:
DMEncrypt = "{{ Error encrypting }}"
Exit Function
End Function
'THIS FUNCTION DECRYPTS THE INPUT
Public Function DMDecrypt(strText As String)
On Error GoTo Xit
Dim Combine As String, i As Integer, Temp As String, Temp2 As Integer
Combine = ""
For i = 1 To Len(strText)
Combine = Combine & Chr(Asc(Mid(strText, i, 1)) - 128)
Next i
Temp = ""
For i = 1 To Len(Combine) Step 3
Temp2 = Mid(Combine, i, 3)
Temp = Temp & Chr(Temp2)
Next i
DMDecrypt = Temp
Exit Function
Xit:
DMDecrypt = "{{ Error encrypting }}"
Exit Function
End Function
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.