Wednesday, November 12, 2008

Reverse Hex Dump

Here's a nasty hack. I needed to automate a VNC user password in a kickstart file. The password, generated by vncpasswd was not easily transportable. Consider this example:
[doug@vinci .vnc]$ vncpasswd
Password: password
Verify: password
[doug@vinci .vnc]$ cat passwd
ÛØ<ýrzX
That's a mess. How are we going to get that into an ASCII file?
[doug@vinci .vnc]$ hexdump passwd
0000000 d8db fd3c 7a72 5814
0000008
Okay: that's hex. But how do we get it back to ASCII?
[doug@vinci .vnc]$ for HEX in d8 db fd 3c 7a 72 58 14; do echo -en "\x$HEX" | awk '{printf "%c", $1}'; done
ØÛý<zrX
With a few stategically placed spaces, it's back into hex.

Ah... It's not quite right. Look at the characters. They're out of order
[doug@vinci hexdump -C passwd
00000000   db d8 3c fd 72 7a 14 58     |..<.rz.X|
00000008
[doug@vinci .vnc]$ for HEX in db d8 3c fd 72 7a 14 58; do echo -en "\x$HEX" | awk '{printf "%c", $1}'; done
ÛØ<ýrzX
Much better. Dare I say perfect. And we don't even need to add the spaces.

No comments:

Post a Comment