做题目学习  https://www.zhihu.com/question/26598476/answer/45396765

http://email.about.com/od/emailbehindthescenes/a/uuencoding.htm

It begins with "begin". It ends with "end". In between, however, are lots and lots of random characters. Or so it seems.

Of course, the characters you see in the email attachment are not random.

They are uuencoded.

Uuencoding is a method of representing arbitrary任意的;武断的;专制的 binary data (such as programs, word processor documents, or images) in plain US-ASCII text.

Why Uuencode? 【一种编码的程式(可将二进制文件编码为文本文件)】

Why would anybody need a way for doing that?

Email was designed for textual messages using only English characters and cannot safely transport text in other languages let alone更不必说 binary files such as images or programs.

When you insert the latter in an email you never know what will come out at the recipient's接受者 end, or if anything will come out at all.

This is why a way to convert binary data to ASCII text (and vice versa反之亦然) was needed.

Uuencoding is one way, and in a sense a predecessor to MIME and its predominant Base64 encoding.

What Uuencoding Does

Like Base64 encoding, uuencoding takes three bytes of binary data and converts them to four bytes of ASCII text (which equals four characters).

每3个字节,拆成对应的4个ASCII文本    8*3拆为6*4

Each byte consists of eight bits.

For the conversion, uuencoding starts by concatenating连结;使连锁 the 24 bits (3 times 8) that make up the three binary data bytes and splitting them into four chunks of six bits each.

To get four complete bytes (which need eight bits but we only have six), '0' characters need to be placed in front of these chunks.  需要补0

We do not want to change the value of the chunks, 007 has the same value has 7.

So far, we have turned three bytes into four bytes by adding superfluous多余的 data and wasting space.

This is necessary to ensure each byte can be represented in ASCII characters.

Another step is necessary before we can begin that conversion, however.

Nonchalantly冷淡地,漠不关心地, we add 32 (100000 in binary notation记号法) to each of the four bytes.    拆出的4个字节,每个+32

This makes sure that the output data is indeed a printable character, which begin with ASCII 32, the white space.

To get the character, we look up the byte value in the ASCII codeset (65, for example, corresponds to 'A').

Now we have a way to transform binary data to ASCII text.

To make it ready for inclusion包含;内含物 in email messages, one more hurdle障碍 is waiting for us to be taken.

While there is no limit to the size of an email message, email servers can and do limit the length of a single line in an email.

We need to insert line breaks into our output data.

This is done after at most 45 characters.   每一行最多45个字符

Since the last line will not always be filled with 45 characters and to introduce a certain amount of data security, each line begins with a character indicating the length of the line. 每一行开头的字符指明了长度

To get this character, we apply the procedure that already got us ASCII characters for our binary bits to the line length: we add 32 and look up the character in the ASCII table.   把长度+32然后转换成对应的ASCII码

If the line is 45 bytes long, for example, we look up 77, which is 'M'. This is why you will find a capital M at the beginning of most lines in a uuencoded file.   长度45,加上32,得到77,对应M

Encoding Example

Let us assume we have three bytes of input: 155, 162 and 233.

The corresponding bit stream is 100110111010001011101001,

which in turn corresponds to the 6-bit values 100110, 111010, 001011 and 101001.

Now we turn these six-bit chunks into full bytes (00100110 = 38, 00111010 = 58, 00001011 = 11 and 00101001 = 41)

and add 32 to get 70 = 01000110, 90 = 01011010, 43 = 00101011 and 73 = 01001001.

Eventually, we look up these numbers in the ASCII table: 70 = F, 90 = Z, 43 = + and 73 = I.

Our input stream converts to the printable characters FZ+I.

FZ+I is 4 bytes long, plus 32 makes 36, which translates to '$'. So the full line of uuencoded data is $FZ+I.

Header and Footer

Only the "begin" and "end" are still missing.

The header line of a uuencoded file consists of the word "begin", the Unix file permission value (something like "664") and the file name.

A header line could look like this, for example: "begin 664 test.bin".

The footer is simply "end". A complete example, thus, would be:

begin 664 test.bin
$FZ+I

end

How Uuencoding Works的更多相关文章

  1. spring注解源码分析--how does autowired works?

    1. 背景 注解可以减少代码的开发量,spring提供了丰富的注解功能.我们可能会被问到,spring的注解到底是什么触发的呢?今天以spring最常使用的一个注解autowired来跟踪代码,进行d ...

  2. [Unity][Heap sort]用Unity动态演示堆排序的过程(How Heap Sort Works)

    [Unity][Heap sort]用Unity动态演示堆排序的过程 How Heap Sort Works 最近做了一个用Unity3D动态演示堆排序过程的程序. I've made this ap ...

  3. How PhoneGap & Titanium Works

    转载自 http://www.appcelerator.com/blog/2012/05/comparing-titanium-and-phonegap/ How PhoneGap Works As ...

  4. Saying that Java is nice because it works on every OS is like saying that anal sex is nice because it works on every gender.

    Saying that Java is nice because it works on every OS is like saying that anal sex is nice because i ...

  5. How Garbage Collection Really Works

    Java Memory Management, with its built-in garbage collection, is one of the language's finest achiev ...

  6. 攻城狮在路上(肆)How tomcat works(零) 前言说明

    最近几篇是关于How tomcat works一书的读书笔记. 通过数个章节逐渐实现一个tomcat的功能. 源码下载地址:http://zhidao.baidu.com/share/7007af0f ...

  7. The Magic only works with total devotion of one's heart

    The Magic only works with total devotion of one's heart All tools and equipments are useless without ...

  8. How Tomcat works — 四、tomcat启动(3)

    上一节说到StandardService负责启动其子组件:container和connector,不过注意,是有先后顺序的,先启动container,再启动connector,这一节先来看看conta ...

  9. How ADB works

    ADB (Android Debug Bridge): How it works? 2012.2.6 early draft Tetsuyuki Kobayashi What is ADB? If y ...

随机推荐

  1. 2-Highcharts 3D图之3D柱状图带可调试倾斜角度

    <!DOCTYPE> <html lang='en'> <head> <title>2-Highcharts 3D图之3D柱状图带可调试倾斜角度< ...

  2. [百度空间] [原]android下的各种坑

    一堆so文件安装不正确: apk里面都是全的, 但是安装完后/data/data/$pkg/lib下面就没有 google了好长时间没有结果.最后发现是因为没库有加lib前缀(当时想了一下觉得不加更好 ...

  3. spring security 构造函数初始化bean思路

    采用有参数的构造方法来解决注入你要的属性例如:public MyInvocationSecurityMetadataSource(RoleService roleService) { this.rol ...

  4. 旨在脱离后端环境的前端开发套件 - IDT之Server篇

    IDT,一个基于Nodejs的,旨在脱离后端环境的前端开发套件,目的就是能让前端开发完全脱离后端的环境,无论后端是什么模板引擎(主流),都能应付自如. IDT主要包括两大部分:Server + Bui ...

  5. Nagios 快速实现数据可视化的几种方式

    Nagios 是一款强大的开源监控软件,但他本身不能绘图,只能查看当前数据,不能看历史数据以及趋势,也正因此,想要更舒适的使用就要搭配绘图软件,现在可搭配的绘图软件有很多,例如 pnp4nagios, ...

  6. LSTM/RNN的应用Case

    作者:许铁-巡洋舰科技链接:https://www.zhihu.com/question/37082800/answer/126430702来源:知乎著作权归作者所有,转载请联系作者获得授权. 作者: ...

  7. 高性能javascript及页面注意事项

    1.少用全局变量 原因:因为作用域链是一个堆栈的结构,所以遵循先进先出的原则,而javascript引擎在解析代码的时候,将全局对象放在栈底,然后向上依次出现的是不同作用域的活动对象(这些活动对象除了 ...

  8. Delphi的Socket编程步骤

    ClientSocket 和ServerSocket几个重要的属性:   1.client和server都有port属性,需要一致才能互相通信   2.client有Address属性,使用时填写对方 ...

  9. 整数划分 Integer Partition(二)

    本文是整数划分的第二节,主要介绍整数划分的一些性质. 一 先来弥补一下上一篇文章的遗留问题:要求我们所取的 (n=m1+m2+...+mi )中  m1 m2 ... mi连续,比如5=1+4就不符合 ...

  10. DB2常用函数:字符串函数

    VALUE函数 语法:VALUE(EXPRESSION1,EXPRESSION2) VALUE函数是用返回一个非空的值,当其第一个参数非空,直接返回该参数的值,如果第一个参数为空,则返回第一个参数的值 ...