Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What is the difference between base64 encoding and ascii encoding?


Asked by Beau Todd on Dec 03, 2021 FAQ



Packs of 6 bits (6 bits have a maximum of 64 different binary values) are converted into 4 numbers (24 = 4 * 6 bits) which are then converted to their corresponding values in Base64. As this example illustrates, Base64 encoding converts 3 uncoded bytes (in this case, ASCII characters) into 4 encoded ASCII characters.
Consequently,
It encodes Unicode codepoints (characters) into bytes. Base64 is a binary-to-text encoding. It encodes bytes to text. You need the latter in this case. Encoding.UTF8.GetString decodes a UTF-8-encoded byte array, which is lossy if there are invalid byte sequences (which is highly likely if you feed it random bytes like a ciphertext).
One may also ask, Therefore instead of using 8 bit digits, the Base64 code uses 6 bit words, i.e. 64 combinations, but maps these 64 digits to ASCII characters from ‘A’ (meaning 0) to ‘/’ meaning 63. The advantage is that to use only legal ASCII characters, that are perfectly compatible with any channel, but to minimize the waste.
Furthermore,
Initially, the algorithm was named as “printable encoding” and only after a couple of years, in June 1992, RFC 1341 defines it as “Base64”. Since this algorithm uses 64 basic characters it was not difficult to give it a name (especially that Base85 already existed).
Also Know,
Base64 Encoding is used encode binary data in order to prevent it from being modified during transit. PHP's base64_encode () function can be used to encode any sequence of bytes to Base64 encoded string.