digest(SoDA)
digest()所属R语言包:SoDA
Create hash function digests for arbitrary R objects
对任意R对象创建散列函数摘要
译者:生物统计家园网 机器人LoveR
描述----------Description----------
The digest function applies a cryptographical hash function to arbitrary R objects. By default, the objects are internally serialized, and either one of the currently implemented MD5 and SHA-1 hash functions algorithms can be used to compute a compact digest of the serialized object.
digest功能应用cryptographical的哈希函数,任意R对象。默认情况下,内部序列化的对象,无论是当前实施的MD5和SHA-1散列函数算法可以用来计算一个紧凑的序列化对象的摘要。
This version of the function accomplishes essentially the same result as the function of the same name in the digest package, but via somewhat different computations, as discussed in the book “Software for Data Analysis”.
digest包中的功能相同的名称,但可以通过一些不同的计算软件进行数据分析的书“,作为讨论的”这个版本的功能实现基本上是相同的结果。
用法----------Usage----------
digest(object, algo=c("md5", "sha1", "crc32"),
serialize=TRUE, file=FALSE, length=Inf, use.Call = FALSE)
参数----------Arguments----------
参数:object
An arbitrary R object which will then be passed to the serialize function, unless the serialize argument is set to FALSE
的任意R对象将被传递给serialize功能,除非serialize参数被设置成FALSE
参数:algo
The algorithms to be used; currently available choices are md5, which is also the default, sha1 and crc32
使用的算法,目前可供选择的是的md5,这也是默认情况下,sha1和crc32
参数:serialize
A logical variable indicating whether the object should be serialized using serialize. Setting this to FALSE allows to compare the digest output of given character strings to known control output.
逻辑型的变量指示是否应被序列化的对象,使用serialize。设置为FALSE,可比较的摘要输出的字符串已知的控制输出。
参数:file
A logical variable indicating whether the object is a file name.
一个逻辑变数,指出对象是否是一个文件名。
参数:length
Number of characters to process. By default, when length is set to Inf, the whole string or file is processed.
要处理的字符数。默认情况下,当length设置为Inf,整个字符串或文件的处理。
参数:use.Call
Should the C interface use the .Call() interface or the .C() interface. An internal question whose answer should not affect the result.
如果C接口使用.Call()接口或.C()接口的。内部问题的答案应该不会影响结果。
Details
详细信息----------Details----------
See the documentation for the digest package version of the function, and the references below for the underlying algorithms.
digest包版本的功能,参考下面的底层算法的文档。
The version in the present package has been modified for tutorial reasons, to illustrate some principles of the design of interfaces to C code.
在目前的包的版本已被修改为教程的原因,来说明一些原则的接口设计为C代码。
值----------Value----------
The digest function returns a character string of a fixed length containing the requested digest of the supplied R object. For MD5, a string of length 32 is returned; for SHA-1, a string of length 40 is returned; for CRC32 a string of length 8.
digest函数返回一个固定长度的字符串包含请求的摘要提供的R对象。对于MD5,SHA-1返回一个字符串,长度为32;,字符串长度为40,则返回一个字符串的长度为8 CRC32。
(作者)----------Author(s)----------
Dirk Eddelbuettel <a href="mailto:edd@debian.org">edd@debian.org</a> for the original <font face="Courier New,Courier" color="#666666"><b>R</b></font> interface;
Antoine Lucas for the integration of crc32; Jarek Tuszynski for the
file-based operationss; Christophe Devine for the hash function
implementations for sha-1 and md5; Jean-loup Gailly and Mark Adler
for crc32.
John Chambers for the modified C and <font face="Courier New,Courier" color="#666666"><b>R</b></font> code in this package.
参考文献----------References----------
C functions used here for sha-1 and md5, and further references.
supplied the code for crc32.
参见----------See Also----------
serialize, md5sum
serialize,md5sum
实例----------Examples----------
## Standard RFC 1321 test vectors[#标准RFC 1321测试向量]
md5Input <-
c("",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
paste("12345678901234567890123456789012345678901234567890123456789012",
"345678901234567890", sep=""))
md5Output <-
c("d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a")
for (i in seq(along=md5Input)) {
md5 <- digest(md5Input[i], serialize=FALSE)
stopifnot(identical(md5, md5Output[i]))
}
sha1Input <-
c("abc",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
NULL)
sha1Output <-
c("a9993e364706816aba3e25717850c26c9cd0d89d",
"84983e441c3bd26ebaae4aa1f95129e5e54670f1",
"34aa973cd4c4daa4f61eeb2bdbad27316534016f")
for (i in seq(along=sha1Input)) {
sha1 <- digest(sha1Input[i], algo="sha1", serialize=FALSE)
stopifnot(identical(sha1, sha1Output[i]))
}
crc32Input <-
c("abc",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
NULL)
crc32Output <-
c("352441c2",
"171a3f5f",
"2ef80172")
for (i in seq(along=crc32Input)) {
crc32 <- digest(crc32Input[i], algo="crc32", serialize=FALSE)
stopifnot(identical(crc32, crc32Output[i]))
}
# one of the FIPS-[一个在FIPS-]
sha1 <- digest("abc", algo="sha1", serialize=FALSE)
stopifnot(identical(sha1, "a9993e364706816aba3e25717850c26c9cd0d89d"))
# example of a digest of a standard R list structure[例如,一个标准的R列表结构的摘要]
digest(list(LETTERS, data.frame(a=letters[1:5], b=matrix(1:10,ncol=2))))
# test 'length' parameter and file input[测试长度参数和文件输入]
fname = file.path(R.home(),"COPYING")
x = readChar(fname, file.info(fname)$size) # read file[读取文件]
for (alg in c("sha1", "md5", "crc32")) {
# partial file[部分文件]
h1 = digest(x , length=18000, algo=alg, serialize=FALSE)
h2 = digest(fname, length=18000, algo=alg, serialize=FALSE, file=TRUE)
h3 = digest( substr(x,1,18000) , algo=alg, serialize=FALSE)
stopifnot( identical(h1,h2), identical(h1,h3) )
# whole file[整个文件]
h1 = digest(x , algo=alg, serialize=FALSE)
h2 = digest(fname, algo=alg, serialize=FALSE, file=TRUE)
stopifnot( identical(h1,h2) )
}
# compare md5 algorithm to other tools[MD5算法来比较其他工具]
library(tools)
fname = file.path(R.home(),"COPYING")
h1 = as.character(md5sum(fname))
h2 = digest(fname, algo="md5", file=TRUE)
stopifnot( identical(h1,h2) )
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|