Results 1 to 3 of 3

Thread: VB6 - bEncode() and bDecode()

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    VB6 - bEncode() and bDecode()

    Simple encode/decode functions, whats so special about them you ask?
    Well, you can recompile the byte map arrays on the fly so your bEncode() can't be bDecoded()'d by others so easily.

    In a module:
    VB Code:
    1. Option Explicit
    2.  
    3. Private bEncodeMap(0 To 255) As Byte
    4. Private bDecodeMap(0 To 255) As Byte
    5.  
    6. Public Sub bInit()
    7.     ' byte arrays go here
    8. End Sub
    9.  
    10. Public Function bEncode(ByRef s As String) As String
    11.     Dim i As Integer
    12.     bEncode = ""
    13.     For i = 1 To Len(s)
    14.         bEncode = bEncode & Chr(bEncodeMap(Asc(Mid$(s, i, 1))))
    15.     Next i
    16. End Function
    17.  
    18. Public Function bDecode(ByRef s As String) As String
    19.     Dim i As Integer
    20.     bDecode = ""
    21.     For i = 1 To Len(s)
    22.         bDecode = bDecode & Chr(bDecodeMap(Asc(Mid$(s, i, 1))))
    23.     Next i
    24. End Function

    In a form:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim s As String
    5.     bInit
    6.     s = "some text to encode"
    7.     s = bEncode(s)
    8.     Debug.Print "Encoded", s
    9.     s = bDecode(s)
    10.     Debug.Print "Decoded", s
    11. End Sub
    Attached Files Attached Files
    Last edited by frozen; Apr 14th, 2006 at 07:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width