base64#451

base64

1 second
64 megabytes
Very hard

You need to implement a converter to and from the base64 format.

Encoding into base64 is performed as follows:

1. If the length of the input text (in bytes) is not divisible by , append the minimum number of zero bytes so that its length becomes divisible by . The number of appended bytes is remembered. 2. The text is divided into groups of bytes. Each group is encoded separately. 3. From these bytes, a -bit number is composed. The first byte is the most significant, and the third byte is the least significant. 4. This -bit number is split into four -bit groups. The highest bits determine the first symbol of the encoding quadruple, the next bits determine the second, and so on. 5. Each -bit group is used as an index into the set:

Index corresponds to the symbol 'A', index to 'B', ..., index to '/'. 6. The resulting four symbols are written one after another in the same order as the bytes from which they were derived. 7. Recall how many zero bytes were added at step , and replace as many final symbols in the encoded text with '='. 8. The encoded text is divided into groups of characters (the last group may be shorter), with each group written on a separate line. Each non-empty line must end with a linefeed (the character codes and ).

Input

The first line contains the type of content in the input file. The second line is blank. The remaining lines contain the data to encode or decode.

If text encoding is required, the input file starts with 'Content-Transfer-Encoding: 8bit', followed by characters with ASCII codes , and then the data to encode (which can contain arbitrary binary data). The data volume does not exceed bytes.

If text decoding is required, the input file starts with 'Content-Transfer-Encoding: base64', followed by characters with ASCII codes , and then the base64-encoded data. The original (decoded) data does not exceed bytes.

Output

First, output the line with the opposite content type (i.e., 'Content-Transfer-Encoding: base64' if the input was bit, and vice versa). The next line must be blank. Then, output the result of encoding or decoding.

If text encoding was required, the output should begin with 'Content-Transfer-Encoding: base64', followed by characters with ASCII codes , and then the base64-encoded text.

If text decoding was required, the output should begin with 'Content-Transfer-Encoding: 8bit', followed by characters with ASCII codes , and then the decoded data.

Examples

Example 1

Loading
Loading