D
D
Dmitry2017-02-06 17:58:11
Character encoding
Dmitry, 2017-02-06 17:58:11

How to decode Base64 (RFC 2045)?

Explain "on the fingers" how to decode Base64 standard RFC 2045 . For the second day, I look at the Base64 page - Wikipedia could not figure out how to decode. I do not tie the question to a specific EP, there is a sheet of paper, a pen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2017-02-06
@MaKvc

Even Wikipedia makes it clear. Every 3 normal bytes are converted into 4 bytes, which allows them to be transmitted in 64 characters.
1. We take three bytes. That's 3 * 8 = 24 bits.
2. We divide them into four bytes in such a way that we enter 6 significant bits into each of the 4 bytes, and fill the two most significant bits with zeros.
3. We get 4 bytes, each of which can have a value from 0 to 63 (because the two most significant bits are zeros).
4. We substitute the necessary characters according to the table from Wikipedia, and we get the ASC2 representation, that is, the BASE64 encoded string.
We repeat all this for the desired length of the sequence, taking three bytes from it. When the bytes run out, in the output string, we fill in the missing up to 4 characters with '="
All.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question