Obfuscating human-readable text by using hexadecimal views.

How to convert to and from hex dumps using xxd


In an earlier article, I explained the use of compiled binary files to hide the code run within them:


However, it is not possible to set environmental variables using this method. MD5 checksums were considered, however, these are NOT reversible, so naturally, we ended up using the hexadecimal representation of our text.


Text File Conversion

Conventionally xxd is used to convert a text file — e.g.

into a hex dump file. Although it is possible to convert into a binary dump using the -b flag, this includes a copy of the initial string which defeats the purpose of what we are after.

Instead, we use the postscript continuous hex dump style produced with the -p flag.

To reverse the process we can use the -r flag

String to Plain HexDump format

Applying the same principle to a text string. Using echo we can redirect a string into xxd and use the same plain hex dump style as before.

This produces the following output:

To convert this back into the string we can use the reverse flag:

and re-obtain our original string.

Setting the ENV variables

Combining this with a pipe we can now set our environmental variables using this non-human readable code:

And here the variable $MYVAR now returns:

And there we have it, a way to set environmental variables using non-human readable text.

Research Software Engineer specialising in Data Visualisation with a touch of HPC. — PhD in Atmospheric Chemistry and Masters in Theoretical Physics.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store