VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



EnHex / DeHex

by Jamie Richard Wilson (2 Submissions)
Category: Encryption
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

EnHex converts a string to hexidecimal characters, which I designed for use with encryption routines that sometimes output unprintable characters. It's a simple way to convert unprintable characters into something printable. DeHex simply reverses the process.

Inputs
EnHex Input: normal text DeHex Input: text that has been "en-hexed"
Assumes
The assumption is that any text sent to DeHex is in fact hexidecimal. I pulled this from my own personal coding toolbox so I haven't built in any error checking because it was written for use in a very controlled environment -- such as apps I've written that use encryption.
Code Returns
EnHex Return: text converted into hexidecimal characters DeHex Return: the original text that was converted to hexidecimal characters using EnHex
Side Effects
Converting a string into hexidecimal format will effectively double the size of the string (hexidecial requires two characters for every "en-hexed character), so be sure to weigh the benefits of having printable text against the size of the result. I tend to only use this if I need to send encrypted data blocks through email or if I want a user to manually enter small amounts of encrypted data, such as a one-line registration number.

Rate EnHex / DeHex

Public Function EnHex(Data As String) As String
  Dim iCount As Double
  Dim sTemp As String
  
  For iCount = 1 To Len(Data)
    sTemp = Hex$(Asc(Mid$(Data, iCount, 1)))
    If Len(sTemp) < 2 Then sTemp = "0" & sTemp
    EnHex = EnHex & sTemp
  Next iCount
End Function
Public Function DeHex(Data As String) As String
  Dim iCount As Double
  For iCount = 1 To Len(Data) Step 2
    DeHex = DeHex & Chr$(Val("&H" & Mid$(Data, iCount, 2)))
  Next iCount
End Function

Download this snippet    Add to My Saved Code

EnHex / DeHex Comments

No comments have been posted about EnHex / DeHex. Why not be the first to post a comment about EnHex / DeHex.

Post your comment

Subject:
Message:
0/1000 characters