Wednesday, 24 October 2012

Base64 Encoding

Although not strictly speaking a cipher (there's no encryption key), Base64 Encoding is important because it allows binary information to be transmitted as text, and so is frequently part of Internet protocols, notably MIME for e-mail. If you look at, say, an MP3 file in a hex editor, you can see the binary, represented in Hex (base 16):


What happens is that the binary data is broken up into from 8-bit bytes into 6-bit segments. These are then replaced by ASCII characters. In the following, the start of the second line in the above example is encoded.

Decimal57553272 10197
Hex (base 16)39372048 6561
Binary 00111001 00110111 00100000 01001000 01100101 01100001
Index 141928 32186 2133
Base64 EncodedOTcgS GVh

You can end up with a file looking something like this:

-----BEGIN PGP MESSAGE-----
Version: GnuPG v2.0.17 (MingW32)

lLtwfrsSgnpfUzopSdKcJjAfA1KE6SFTASBoH8JpnXV4AMrmMJVteTpeXr2nftHq
N8BUidauDqNvhKLADWWm5VhvnD7pkbNUv9nshW3SBT3jtmM/xxB3dNxeIfmSc78T
Z5jlEAjHVpS36KJNZSX+tn4fh8TDiTaw/yFOPxdZmwRXdN+fxAvao0/qq+dfsLQw
U5ELc/RavLf01iYwUrrdu97DUJwoLJIh/rxk2hdjgLY8cZRRexmGugb/tvojbq2L
EdOwa4d1gvDX/DYkYeOC4cCiACqwtTIk8IF+aqfrQ9BN2aVD0iuwm0QKqLsRNgxp
YMjtmF9T3UDmotfVsCNxx/HEaGwhU16VP+td9auMTVD124iQkeGFZfNMNynaeizp
bfRe5+OrzmyKVV/evQVlrHXag3RpG4UQx8yed/R+Ed7opd9KZgKT
=76xn
-----END PGP MESSAGE-----

No comments:

Post a Comment