Search Tools Links Login

Simple Hex Encode / Decode


Visual Basic 6, or VB Classic

Two functions: One to turn an ASCII string into a HEX string, and one to turn a HEX string into an ASCII string.

Original Author: Snytax

Code

'Encodes a string as hex
Public Function sHexEncode(sData As String) As String
Dim iChar As Integer
Dim sOutString As String
Dim sTmpChar As String
For iChar = 1 To Len(sData)
  sTmpChar = Hex$(Asc(Mid(sData, iChar, 1)))
  If Len(sTmpChar) = 1 Then sTmpChar = "0" & sTmpChar
  sOutString = sOutString & sTmpChar
Next iChar
sHexEncode = sOutString
End Function
'Decodes a string from hex
Public Function sHexDecode(sData As String) As String
Dim iChar As Integer
Dim sOutString As String
Dim sTmpChar As String
For iChar = 1 To Len(sData) Step 2
  sTmpChar = Chr("&H" & Mid(sData, iChar, 2))
  sOutString = sOutString & sTmpChar
Next iChar
sHexDecode = sOutString
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 148 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.