# Effective Encryption Algorithm

Posted: 2002-06-01
By: ArchiveBot
Viewed: 71

Filed Under:

VB6 Code Cache

No attachments for this post

Encrypts and decrypts strings

Original Author: Micah Ellett

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 INPUTPublic Function DMEncrypt(strText As String)On Error GoTo XitDim Combine As String, i As Integer, Temp As StringCombine = ""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 & TempNext iTemp = ""For i = 1 To Len(Combine)  Temp = Temp & Chr(Asc(Mid(Combine, i, 1)) + 128)Next iDMEncrypt = TempClipboard.SetText TempExit FunctionXit:DMEncrypt = "{{ Error encrypting }}"Exit FunctionEnd Function'THIS FUNCTION DECRYPTS THE INPUTPublic Function DMDecrypt(strText As String)On Error GoTo XitDim Combine As String, i As Integer, Temp As String, Temp2 As IntegerCombine = ""For i = 1 To Len(strText)  Combine = Combine & Chr(Asc(Mid(strText, i, 1)) - 128)Next iTemp = ""For i = 1 To Len(Combine) Step 3  Temp2 = Mid(Combine, i, 3)  Temp = Temp & Chr(Temp2)Next iDMDecrypt = TempExit FunctionXit:DMDecrypt = "{{ Error encrypting }}"Exit FunctionEnd Function`