VB icon

EnHex / DeHex

Email
Submitted on: 1/7/2015 9:23:00 PM
By: Jamie Richard Wilson (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0, VB Script, ASP (Active Server Pages)
Views: 642
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: EnHex / DeHex
' Description: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.
' By: Jamie Richard Wilson (from psc cd)
'
' Inputs:EnHex Input: normal text
DeHex Input: text that has been "en-hexed"
'
' Returns:EnHex Return: text converted into hexidecimal characters
DeHex Return: the original text that was converted to hexidecimal characters using EnHex
'
' 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.
'
' 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.
'**************************************

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


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.