<s>
uuencoding	O
is	O
a	O
form	O
of	O
binary-to-text	O
encoding	O
that	O
originated	O
in	O
the	O
Unix	B-Application
programs	O
uuencode	O
and	O
uudecode	B-Device
written	O
by	O
Mary	O
Ann	O
Horton	O
at	O
the	O
University	O
of	O
California	O
,	O
Berkeley	O
in	O
1980	O
,	O
for	O
encoding	O
binary	O
data	O
for	O
transmission	O
in	O
email	O
systems	O
.	O
</s>
<s>
The	O
name	O
"	O
uuencoding	O
"	O
is	O
derived	O
from	O
Unix-to-Unix	B-Protocol
Copy	I-Protocol
,	O
i.e.	O
</s>
<s>
"	O
Unix-to-Unix	O
encoding	O
"	O
is	O
a	O
safe	O
encoding	O
for	O
the	O
transfer	O
of	O
arbitrary	O
files	O
from	O
one	O
Unix	B-Application
system	I-Application
to	O
another	O
Unix	B-Application
system	I-Application
but	O
without	O
guarantee	O
that	O
the	O
intervening	O
links	O
would	O
all	O
be	O
Unix	B-Application
systems	I-Application
.	O
</s>
<s>
Since	O
an	O
email	O
message	O
might	O
be	O
forwarded	O
through	O
or	O
to	O
computers	O
with	O
different	O
character	B-General_Concept
sets	I-General_Concept
or	O
through	O
transports	O
which	O
are	O
not	O
8-bit	O
clean	O
,	O
or	O
handled	O
by	O
programs	O
that	O
are	O
not	O
8-bit	O
clean	O
,	O
forwarding	O
a	O
binary	O
file	O
via	O
email	O
might	O
cause	O
it	O
to	O
be	O
corrupted	O
.	O
</s>
<s>
By	O
encoding	O
such	O
data	O
into	O
a	O
character	O
subset	O
common	O
to	O
most	O
character	B-General_Concept
sets	I-General_Concept
,	O
the	O
encoded	O
form	O
of	O
such	O
data	O
files	O
was	O
unlikely	O
to	O
be	O
"	O
translated	O
"	O
or	O
corrupted	O
,	O
and	O
would	O
thus	O
arrive	O
intact	O
and	O
unchanged	O
at	O
the	O
destination	O
.	O
</s>
<s>
The	O
program	O
uudecode	B-Device
reverses	O
the	O
effect	O
of	O
uuencode	O
,	O
recreating	O
the	O
original	O
binary	O
file	O
exactly	O
.	O
</s>
<s>
uuencode/decode	O
became	O
popular	O
for	O
sending	O
binary	O
(	O
and	O
especially	O
compressed	O
)	O
files	O
by	O
email	O
and	O
posting	O
to	O
Usenet	B-Application
newsgroups	O
,	O
etc	O
.	O
</s>
<s>
It	O
has	O
now	O
been	O
largely	O
replaced	O
by	O
MIME	B-Protocol
and	O
yEnc	O
.	O
</s>
<s>
With	O
MIME	B-Protocol
,	O
files	O
that	O
might	O
have	O
been	O
uuencoded	O
are	O
instead	O
transferred	O
with	O
Base64	B-Protocol
encoding	I-Protocol
.	O
</s>
<s>
<mode>	O
is	O
the	O
file	O
's	O
Unix	B-Application
file	O
permissions	O
as	O
three	O
octal	O
digits	O
(	O
e.g.	O
</s>
<s>
This	O
is	O
typically	O
only	O
significant	O
to	O
Unix-like	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
<length character>	O
is	O
a	O
character	O
indicating	O
the	O
number	O
of	O
data	O
bytes	B-Application
which	O
have	O
been	O
encoded	O
on	O
that	O
line	O
.	O
</s>
<s>
This	O
is	O
an	O
ASCII	B-Protocol
character	I-Protocol
determined	O
by	O
adding	O
32	O
to	O
the	O
actual	O
byte	B-Application
count	O
,	O
with	O
the	O
sole	O
exception	O
of	O
a	O
grave	O
accent	O
"	O
`	O
"	O
(	O
ASCII	B-Protocol
code	I-Protocol
96	O
)	O
signifying	O
zero	O
bytes	B-Application
.	O
</s>
<s>
All	O
data	O
lines	O
,	O
except	O
the	O
last	O
(	O
if	O
the	O
data	O
length	O
was	O
not	O
divisible	O
by	O
45	O
)	O
,	O
have	O
45	O
bytes	B-Application
of	O
encoded	O
data	O
(	O
60	O
characters	O
after	O
encoding	O
)	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
vast	O
majority	O
of	O
length	O
values	O
are	O
'	O
M	O
 '	O
,	O
(	O
32	O
+	O
45	O
=	O
ASCII	B-Protocol
code	I-Protocol
77	O
or	O
"	O
M	O
"	O
)	O
.	O
</s>
<s>
The	O
second	O
to	O
last	O
line	O
is	O
also	O
a	O
character	O
indicating	O
the	O
line	O
length	O
,	O
with	O
the	O
grave	O
accent	O
signifying	O
zero	O
bytes	B-Application
.	O
</s>
<s>
The	O
mechanism	O
of	O
uuencoding	O
repeats	O
the	O
following	O
for	O
every	O
3	O
bytes	B-Application
,	O
encoding	O
them	O
into	O
4	O
printable	O
characters	O
,	O
each	O
character	O
representing	O
a	O
radix-64	O
numerical	O
digit	O
:	O
</s>
<s>
Start	O
with	O
3	O
bytes	B-Application
from	O
the	O
source	O
,	O
24	O
bits	O
in	O
total	O
.	O
</s>
<s>
Output	O
the	O
ASCII	B-Protocol
equivalent	O
of	O
these	O
numbers	O
.	O
</s>
<s>
If	O
the	O
source	O
length	O
is	O
not	O
divisible	O
by	O
3	O
,	O
then	O
the	O
last	O
4-byte	O
section	O
will	O
contain	O
padding	O
bytes	B-Application
to	O
make	O
it	O
cleanly	O
divisible	O
.	O
</s>
<s>
These	O
bytes	B-Application
are	O
subtracted	O
from	O
the	O
line	O
's	O
<length character>	O
so	O
that	O
the	O
decoder	O
does	O
not	O
append	O
unwanted	O
characters	O
to	O
the	O
file	O
.	O
</s>
<s>
uudecoding	O
is	O
reverse	O
of	O
the	O
above	O
,	O
subtract	O
32	O
from	O
each	O
character	O
's	O
ASCII	B-Protocol
code	I-Protocol
(	O
modulo	O
64	O
to	O
account	O
for	O
the	O
grave	O
accent	O
usage	O
)	O
to	O
get	O
a	O
6-bit	O
value	O
,	O
concatenate	O
4	O
6-bit	O
groups	O
to	O
get	O
24	O
bits	O
,	O
then	O
output	O
3	O
bytes	B-Application
.	O
</s>
<s>
The	O
following	O
table	O
shows	O
the	O
conversion	O
of	O
the	O
decimal	O
value	O
of	O
the	O
6-bit	O
fields	O
obtained	O
during	O
the	O
conversion	O
process	O
and	O
their	O
corresponding	O
ASCII	B-Protocol
character	I-Protocol
output	O
code	O
and	O
character	O
.	O
</s>
<s>
In	O
this	O
example	O
,	O
%0D	O
is	O
the	O
byte	B-Application
representation	O
for	O
carriage	O
return	O
,	O
and	O
%0A	O
is	O
the	O
byte	B-Application
representation	O
for	O
line	O
feed	O
.	O
</s>
<s>
Unix	B-Application
traditionally	O
has	O
a	O
single	O
fork	B-Application
where	O
file	O
data	O
is	O
stored	O
.	O
</s>
<s>
However	O
,	O
some	O
file	O
systems	O
support	O
multiple	O
forks	B-Application
associated	O
with	O
a	O
single	O
file	O
.	O
</s>
<s>
For	O
example	O
,	O
classic	O
MacOS	O
Hierarchical	B-Application
File	I-Application
System	I-Application
(	O
HFS	B-Application
)	O
supported	O
a	O
data	B-Operating_System
fork	I-Operating_System
and	O
a	O
resource	B-Operating_System
fork	I-Operating_System
.	O
</s>
<s>
MacOS	O
HFS+	B-Application
supports	O
multiple	O
forks	B-Application
,	O
as	O
does	O
Microsoft	O
Windows	O
NTFS	B-Application
alternate	O
data	O
streams	O
.	O
</s>
<s>
Most	O
uucoding	O
tools	O
will	O
only	O
handle	O
data	O
from	O
the	O
primary	O
data	B-Operating_System
fork	I-Operating_System
,	O
which	O
can	O
result	O
in	O
a	O
loss	O
of	O
information	O
when	O
encoding/decoding	O
(	O
for	O
example	O
,	O
Windows	O
NTFS	B-Application
file	O
comments	O
are	O
kept	O
in	O
a	O
different	O
fork	B-Application
)	O
.	O
</s>
<s>
Some	O
tools	O
(	O
like	O
the	O
classic	O
MacOS	O
application	O
UUTool	B-Operating_System
)	O
solved	O
the	O
problem	O
by	O
concatenating	O
the	O
different	O
forks	B-Application
into	O
one	O
file	O
and	O
differentiating	O
them	O
by	O
file	O
name	O
.	O
</s>
<s>
Despite	O
its	O
limited	O
range	O
of	O
characters	O
,	O
uuencoded	O
data	O
is	O
sometimes	O
corrupted	O
on	O
passage	O
through	O
certain	O
computers	O
using	O
non-ASCII	O
character	O
sets	O
such	O
as	O
EBCDIC	B-Language
.	O
</s>
<s>
More	O
common	O
today	O
is	O
the	O
Base64	B-Protocol
format	O
,	O
which	O
is	O
based	O
on	O
the	O
same	O
concept	O
of	O
alphanumeric-only	O
as	O
opposed	O
to	O
ASCII	B-Protocol
32	O
–	O
95	O
.	O
</s>
<s>
Base64	B-Protocol
can	O
also	O
be	O
generated	O
by	O
the	O
uuencode	O
program	O
and	O
is	O
similar	O
in	O
format	O
,	O
except	O
for	O
the	O
actual	O
character	O
translation	O
:	O
</s>
<s>
Another	O
alternative	O
is	O
Ascii85	O
,	O
which	O
encodes	O
four	O
binary	O
characters	O
in	O
five	O
ASCII	B-Protocol
characters	I-Protocol
.	O
</s>
<s>
Ascii85	O
is	O
used	O
in	O
PostScript	B-Language
and	O
PDF	B-Application
formats	I-Application
.	O
</s>
<s>
uuencoding	O
takes	O
3	O
pre-formatted	O
bytes	B-Application
and	O
turns	O
them	O
into	O
4	O
and	O
also	O
adds	O
begin/end	O
tags	O
,	O
filename	O
,	O
and	O
delimiters	B-Algorithm
.	O
</s>
<s>
The	O
Python	B-Language
language	I-Language
supports	O
uuencoding	O
using	O
the	O
codecs	O
module	O
with	O
the	O
codec	O
"	O
uu	O
"	O
:	O
</s>
<s>
For	O
Python	B-Language
2	O
(	O
deprecated/sunset	O
as	O
of	O
January	O
1st	O
2020	O
)	O
:	O
</s>
<s>
For	O
Python	B-Language
3	O
where	O
the	O
codecs	O
module	O
needs	O
to	O
be	O
imported	O
and	O
used	O
directly	O
:	O
</s>
<s>
The	O
Perl	B-Language
language	I-Language
supports	O
uuencoding	O
natively	O
using	O
the	O
pack( )	O
and	O
unpack( )	O
operators	O
with	O
the	O
format	O
string	O
"	O
u	O
"	O
:	O
</s>
<s>
Decoding	O
base64	B-Protocol
with	O
unpack	O
can	O
likewise	O
be	O
accomplished	O
by	O
translating	O
the	O
characters	O
:	O
</s>
