Uuencoding
≈ 6 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
uuencoding is a form of binary-to-text encoding that originated in the Unix programs uuencode and uudecode written by Mary Ann Horton at the University of California, Berkeley in 1980, for encoding binary data for transmission in email systems. The name "uuencoding" is derived from Unix-to-Unix Copy, i.e. "Unix-to-Unix encoding" is a safe encoding for the transfer of arbitrary files from one Unix system to another Unix system but without guarantee that the intervening links would all be Unix systems.
Evidence and sources
Since an email message might be forwarded through or to computers with different character sets or through transports which are not 8-bit clean, or handled by programs that are not 8-bit clean, forwarding a binary file via email might cause it to be corrupted. By encoding such data into a character subset common to most character sets, the encoded form of such data files was unlikely to be "translated" or corrupted, and would thus arrive intact and unchanged at the destination.
Impact
The program uudecode reverses the effect of uuencode, recreating the original binary file exactly. uuencode/decode became popular for sending binary (and especially compressed) files by email and posting to Usenet newsgroups, etc. It has now been largely replaced by MIME and yEnc. With MIME, files that might have been uuencoded are instead transferred with Base64 encoding.
uuencoding is a form of binary-to-text encoding that originated in the Unix programs uuencode and uudecode written by Mary Ann Horton at the University of California, Berkeley in 1980, for encoding binary data for transmission in email systems. The name "uuencoding" is derived from Unix-to-Unix Copy, i.e. "Unix-to-Unix encoding" is a safe encoding for the transfer of arbitrary files from one Unix system to another Unix system but without guarantee that the intervening links would all be Unix systems.
Since an email message might be forwarded through or to computers with different character sets or through transports which are not 8-bit clean, or handled by programs that are not 8-bit clean, forwarding a binary file via email might cause it to be corrupted. By encoding such data into a character subset common to most character sets, the encoded form of such data files was unlikely to be "translated" or corrupted, and would thus arrive intact and unchanged at the destination.
The program uudecode reverses the effect of uuencode, recreating the original binary file exactly. uuencode/decode became popular for sending binary (and especially compressed) files by email and posting to Usenet newsgroups, etc. It has now been largely replaced by MIME and yEnc. With MIME, files that might have been uuencoded are instead transferred with Base64 encoding. is a character indicating the number of data bytes which have been encoded on that line.
How it works
This is an ASCII character determined by adding 32 to the actual byte count, with the sole exception of a grave accent "`" (ASCII code 96) signifying zero bytes. All data lines, except the last (if the data length was not divisible by 45), have 45 bytes of encoded data (60 characters after encoding). Therefore, the vast majority of length values are 'M' (32 + 45 = ASCII code 77 or "M"). are encoded characters. See for more details on the actual implementation.
The file ends with two lines: ` end The second to last line is also a character indicating the line length, with the grave accent signifying zero bytes. As a complete file, the uuencoded output for a plain text file named cat.txt containing only the characters Cat would be begin 644 cat.txt #0V%T ` end The begin line is a standard uuencode header; the '#' indicates that its line encodes three characters; the last two lines appear at the end of all uuencoded files.
File Name = wikipedia-url.txt File Contents = http://www.wikipedia.org%0D%0A uuencoding begin 644 wikipedia-url.txt ::'1T $ python -c 'print "Cat".encode("uu")' begin 666 0V%T end $ For Python 3 where the codecs module needs to be imported and used directly: $ python3 -c "from codecs import encode;print(encode(b'Cat', 'uu'))" b'begin 666 \n#0V%T\n \nend\n' $ To decode, pass the whole file: $ python3 -c "from codecs import decode;print(decode(b'begin 666 \n#0V%T\n \nend\n', 'uu'))" b'Cat' $ perl -e 'print pack("u","Cat")' 0V%T Decoding base64 with unpack can likewise be accomplished by translating the characters: $ perl -e 'print unpack("u","#0V%T")' Cat To produce wellformed uuencoded files, you need to use modules, or a little bit more of code: $ perl -ple 'BEGIN{use File::Basename;$/=undef;$sn=basename($ARGV[0]);} $_= "begin 600 $sn\n".(pack "u", $_)."`\nend" if $_' /some/file/to_encode.gz $ php -r "echo convert_uuencode('Cat');" 0V%T ` Decoding is done with the corresponding convert_uudecode() function: $ php -r "echo convert_uudecode('#0V%T');" Cat
Text derived from https://en.wikipedia.org/w/index.php?oldid=1375679165 under CC BY-SA 4.0; modifications have been made.