UUencode 校验和错误

发布于 2024-11-16 19:24:47 字数 351 浏览 4 评论 0原文

我有一个数据流,我尝试使用 UUencode 进行编码,以便将数据传递到外部芯片。该芯片一次接受 512 字节的原始数据。我用 UUencode 编码 512 字节。

据我了解,数据应转换为 11 行 45 字节(编码后为 60 字节)和剩余 1 行 17 字节。

显然,17 个字节不能直接映射到 uuencoded 段,因为它不是 3 的倍数,但是当我取回 uuencoded 数据时,最后一行返回 24 个编码字节(或 18 个原始字节)。

这意味着我现在总共有 513 字节的数据。我的问题是,这是我的 uuencode 算法的错误吗(尽管从纯粹的数学角度来看,我看不出它是怎么回事),或者,额外的字节从哪里来,我该如何再次摆脱它?

I have a stream of data that im attempting to encode with UUencode, in order to pass the data on to an external chip. The chip accepts 512 bytes of raw data at once. I encode 512 bytes with UUencode.

As far as i understand, the data should be converted into 11 lines of 45 bytes (which will be 60 bytes after encoding) and 1 remaining line of 17 bytes.

Obviously the 17 bytes cant map directly to uuencoded segments as it isnt a multiple of 3, yet when i get the uuencoded data back, the final line returns 24 encoded bytes (or 18 raw bytes).

This means that i now have 513 bytes of data in total. My question is, is this a fault with my uuencode algorithm (although from a purely mathematical perspective i cant see how it can be) or alternatively, where does the extra byte come from, and how do i get rid of it again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七禾 2024-11-23 19:24:47

UUEncoding 512 字节将得到 684 编码字节(不是 513)。长度为 384 字节的输入数据流将恰好编码为 512 字节。

UUEncoding 只是一种将 3 个二进制字节输入数据段转换为 4 个文本字节输出数据段的方法。任何长度不是 3 字节的输入段都将用空字节填充,直到达到 3 字节长为止。 UUEncoding 算法没有原始数据长度的表示。

将此与 UUEncoded 文件进行对比,UUEncoded 文件通过将流分成特定长度的行并在每个编码数据行的前面添加行长度指示符来格式化数据流并将信息添加到数据流中。在您的示例中,最后 17 个字节将被编码为 24 字节,但这行数据前面将有一个字节,该字节将行的长度指定为 17 而不是 18。

消除填充的唯一方法是首先通过对数据的长度进行编码来知道它的存在。

UUEncoding 512 bytes will get you 684 encoded bytes (not 513). An input data stream of length 384 bytes will encode to exactly 512 bytes.

UUEncoding is simply a means to transform a 3 binary byte input data segment into a 4 text byte output data segment. Any input segment that is not 3 bytes long is padded with null bytes until it is. The UUEncoding algorithm has no representation for the original data length.

Contrast this with UUEncoded files which format and add information to the data stream by breaking the stream into lines of a specific length and add a line length indicator to the front of each encoded line of data. In your example, your 17 final bytes would be encoded to 24 bytes, but this line of data would be preceded by a byte that gives the length of the line as 17 instead of 18.

The only way to get rid of the padding is to know it is there in the first place by encoding the length of the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文