0
$\begingroup$

I know the basics about base64 encoding, but thinking about it abstractly I have a theoretical question.

If we consider base64 a mathematical function(in our case computable), Does there exists an invariant for base64-encoding function ? It only make sense or to narrow down the scope of the question I assume input binary is ASCII string.

For given ASCII string we can convert it to base64 encoded string in following way

user@machine$ echo "Many hands make light work." | base64
TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsuCg==

How can I find a ASCII string whose base64 representation is same as its input, if it exists ?

Is there any way to prove it's non-existence ?

$\endgroup$
2
  • 1
    $\begingroup$ Isn't it obvious that coding 6 bits in a single byte will make a longer string ? Even if you assume that the two leading bits are zeroes, there is no matching between single ASCII characters up to 64 and their Base64 encoding. $\endgroup$
    – user16034
    Commented Mar 18, 2023 at 10:09
  • $\begingroup$ Slightly more interesting would be: Is there a sequence of bytes that is a prefix of its base-64 encoding? Or: What is the largest possible common prefix of a sequence of bytes and its base-64 encoding? $\endgroup$
    – gnasher729
    Commented Mar 22, 2023 at 21:57

1 Answer 1

3
$\begingroup$

The base64 encoding of the empty string is the empty string, so arguably the empty string could be considered an example of the sort you are looking for. But there are no other examples. The base64 encoding of any (non-zero-length) string is always longer than the string itself.

$\endgroup$
4
  • $\begingroup$ Well, there is the zero length string I suppose. Doesn't help if you want to find an invariant though. $\endgroup$ Commented Mar 18, 2023 at 10:25
  • $\begingroup$ @MaartenBodewes nope: echo "" | base64 yields Cg==. $\endgroup$
    – Kai
    Commented Mar 20, 2023 at 3:31
  • 1
    $\begingroup$ @Kai Yes, and echo -n "" | base64 yields? $\endgroup$ Commented Mar 20, 2023 at 7:57
  • $\begingroup$ Indeed! My bad. So base64 does have a fixpoint. $\endgroup$
    – Kai
    Commented Mar 21, 2023 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.