How do I get hex blocks from a base 64 encoded string?

Ehryk picture Ehryk · Nov 7, 2013 · Viewed 18.4k times · Source

In this article and this XKCD, they both show the password data as groupings of hexadecimal.

However, in the file it's base64 encoded. What could I use to match that output with bash scripting? I've tried:

echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -d
echo -n "7WkoOEfwfTTioxG6CatHBw==" | openssl enc -d -base64

What is it they are doing, and how do I decode them to hex blocks?

xkcd Encryptic

Answer

Digital Trauma picture Digital Trauma · Nov 7, 2013

If I understand this correctly, I think the requirement is to translate a base64 encoded string to a hex string in blocks of 8 bytes (16 hex digits). If so, od -t x8 -An, after the base64 decoding will get you there:

$ echo -n "7WkoOEfwfTTioxG6CatHBw==" | base64 -d | od -t x8 -An
 347df047382869ed 0747ab09ba11a3e2
$