Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sentence that uses every base64 character

Tags:

base64

I am trying to construct a sentence/letter combination that will return every base64 character, but failing to find a word for purposes of unit testing.

The unit tests I have so far are failing to hit the lines that handle the + and / characters. While I can sling a them at the encoder/decoder directly it would be nice to have a human readable source (the base64 equivalent of 'the quick brown dog').

like image 778
graham.reeds Avatar asked Jul 09 '10 14:07

graham.reeds


People also ask

What does == mean in Base64?

When decoding Base64 text, four characters are typically converted back to three bytes. The only exceptions are when padding characters exist. A single = indicates that the four characters will decode to only two bytes, while == indicates that the four characters will decode to only a single byte. For example: Encoded.

What is == At the end of Base64 string?

The equals sign "=" represents a padding, usually seen at the end of a Base64 encoded sequence. The size in bytes is divisible by three (bits divisible by 24): All bits are encoded normally.

What encoding ends with ==?

A Base64 string will end with == if and only if the number of bytes it encodes, mod 3, equals 1. Do you see the pattern? It happens that 16-byte (128-bit) encryption keys are very commonly encoded in Base64, and since 16 mod 3 = 1, their encoding will end with == .

What does == mean at the end of a string?

The equality operator ( == ) checks whether its two operands are equal, returning a Boolean result.


2 Answers

Here is a Base64 encoded test string that includes all 64 possible Base64 symbols:

char base64_encoded_test[] =
"U28/PHA+VGhpcyA0LCA1LCA2LCA3LCA4LCA5LCB6LCB7LCB8LCB9IHRlc3RzIEJhc2U2NCBlbmNv"
"ZGVyLiBTaG93IG1lOiBALCBBLCBCLCBDLCBELCBFLCBGLCBHLCBILCBJLCBKLCBLLCBMLCBNLCBO"
"LCBPLCBQLCBRLCBSLCBTLCBULCBVLCBWLCBXLCBYLCBZLCBaLCBbLCBcLCBdLCBeLCBfLCBgLCBh"
"LCBiLCBjLCBkLCBlLCBmLCBnLCBoLCBpLCBqLCBrLCBsLCBtLCBuLCBvLCBwLCBxLCByLCBzLg==";

char base64url_encoded_test[] =
"U28_PHA-VGhpcyA0LCA1LCA2LCA3LCA4LCA5LCB6LCB7LCB8LCB9IHRlc3RzIEJhc2U2NCBlbmNv"
"ZGVyLiBTaG93IG1lOiBALCBBLCBCLCBDLCBELCBFLCBGLCBHLCBILCBJLCBKLCBLLCBMLCBNLCBO"
"LCBPLCBQLCBRLCBSLCBTLCBULCBVLCBWLCBXLCBYLCBZLCBaLCBbLCBcLCBdLCBeLCBfLCBgLCBh"
"LCBiLCBjLCBkLCBlLCBmLCBnLCBoLCBpLCBqLCBrLCBsLCBtLCBuLCBvLCBwLCBxLCByLCBzLg==";

It decodes to a string composed entirely of relatively human-readable text:

char test_string[] = "So?<p>"
    "This 4, 5, 6, 7, 8, 9, z, {, |, } tests Base64 encoder. "
    "Show me: @, A, B, C, D, E, F, G, H, I, J, K, L, M, "
    "N, O, P, Q, R, S, T, U, V, W, X, Y, Z, [, \\, ], ^, _, `, "
    "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s.";

This decoded string contains only letters in the limited range of isprint()'able 7-bit ASCII characters (space through '~').

Since I did it, I would argue that it is possible :-).

like image 185
David Cary Avatar answered Sep 21 '22 15:09

David Cary


You probably can't do that.

/ in base64 encodes 111111 (6 '1' bits).

As all ASCII (which are the type-able and printable characters) are in the range of 0-127 (i.e. 00000000 and 01111111), the only ASCII character that could be encoded using '/' is the ASCII character with the code 127, which is the non-printable DEL character.

If you allow values higher than 127, you could have a printable but non-typeable string.

like image 26
adamk Avatar answered Sep 24 '22 15:09

adamk