VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple Hex Encode / Decode

by syntax. (6 Submissions)
Category: Encryption
Compatability: VB Script
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

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

Rate Simple Hex Encode / Decode

'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

Download this snippet    Add to My Saved Code

Simple Hex Encode / Decode Comments

No comments have been posted about Simple Hex Encode / Decode. Why not be the first to post a comment about Simple Hex Encode / Decode.

Post your comment

Subject:
Message:
0/1000 characters