UUencode encoding (a contraction of Unix-to-Unix encode) is an algorithm for converting 8-bit binary data into a 7-bit format.
Uuencoding was originally created for sending binary files using the email protocol uucp.
The uucp system translated the character sets used by different systems, and could not distinguish the body of a message from an attachment. For this reason, Uuencode was designed in order to convert binary files into a text format compatible with email, and did not include characters that could mistakenly be converted, which would have rendered the attachment unreadable.
Decoding that involves locating a binary file within a Uuencoded file is called Uudecoding.
Format of a Uuencoded file
A Uuencode file begins with a line of the following form:
begin mode file_name
Principle of Uuencoding
Uuencoding involves taking groups of 3 bytes (24 bits) and treating them as 4 groups of 6 bits, represented by the values 0 to 63 inclusive. If there are less than 24 bits in the inflow, Uuencode fills out the rest with zeroes.
Uuencode adds 32 (decimal) to each value, in order to get a value which corresponds to a printable ASCII character.
The data is represented on lines of 60 characters. Therefore, each line can be used to encode 45 bytes of inflow, as 4 bytes of output represent 3 bytes of input.
Each line is preceded by a character showing how many characters the line has.
After all of the encoded data comes a line which only contains a space, followed by a line containing the string end. The space before the final line is sometimes replaced with ASCII character 96 (grave accent), as certain email clients delete empty lines.