base64
Required to write the converter in base64 format and from base64.
Encoding in base64 is as follows:
1. If the length of the source text, in bytes is not divisible by 3, then it is supplemented by a minimum of zero bytes so that the length was divided by 3, the number of bytes added remembered.
2. The text is divided into groups of 3 bytes. Each group is coded separately.
3. Of the three bytes get 24-bit number. The first byte of the troika is a senior, the third - the youngest.
4. 24-bit number is divided into four 6-bit groups. Senior 6 bit character encoding specifies the first four, the lower 6 bits - the latter etc.
5. Six bits of coded symbols next set:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Number 0 is encoded by the letter 'A', number 1 by the letter 'B', number 63 with '/'.
6. These four characters are written one after another in the same order in which were three of which they were received.
7. I remember how many null characters were added to the end of the source text in step 1, and so the last character encoded text changed to '='.
8. The text is divided into groups of 76 characters (the latter may be less) and each group is recorded in a separate line. Every non-empty line must end with a linefeed (the characters 13 10).
Input
The first line contains the type of information in the input file, the second line is blank, followed by the information that you want to encode or decode.
If you want to encode the text, the file begins with a 'Content-Transfer-Encoding: 8bit', followed by 4characters 13 10 13 10 — and the rest of the file - a set of bytes to be coding. The volume of the encoded text ( "text" can be binary data) does not exceed 100 000 bytes.
If you want to decode the text, the file begins with a 'Content-Transfer-Encoding 'Content-Transfer-Encoding: base64', followed by 4 characters 13 10 13 10 — and the rest of the file - text encoded base64. The coded text was obtained from a source that does not exceed 100 000 bytes.
Output
Remove the string with the opposite type of information, then an empty string, then the result of encoding or decoding.
If required to encode the text, the output should start characters 'Content-Transfer-Encoding: base64', followed by the 4 symbols 13 10 13 10 — continue until the end of the file should contain text encoded in base64.
If required to decode the text, the output should start characters'Content-Transfer-Encoding: 8bit', followed by the 4 symbols 13 10 13 10 — continue until the end of the file should contain the decoded text.