|
|
digest `hash' summaries for arbitrary GNU R objects | |||||
|
Bio Code rcpp rinside rquantlib rpostgresql rprotobuf rvowpalwabbit rdieharder littler random digest beancounter smtm yahooquote octave-mt octave-pg Papers Talks Linux Quantian About Blog
|
Overviewdigest provides `hash' function summaries for GNU R objects. The md5, sha-1, sha-256 and crc32 hash functions are available. The md5 algorithm by Ron Rivest is specified in RFC 1321, the SHA-1 and SHA-256 algorithm is specified in FIPS-180-1 and FIPS-180-2, respectively, and the crc32 algorithm is described in here. For md5, sha-1 and sha-256, this packages uses small standalone C implementations that were provided by by Christophe Devine. For crc32, code from the zlib library is used. For sha-512, a routine by Aaron Gifford is used. Please note that this package is not meant to be deployed for cryptographic purposes for which more comprehensive (and widely tested) libraries such as OpenSSL should be used. ExampleThe following verbatim R session loads digest and runs theexample() from the corresponding
help page:
> library(digest)
> example(digest)
digest> md5Input <- c("", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
paste("12345678901234567890123456789012345678901234567890123456789012",
"34567890123456 ..." ... [TRUNCATED]
digest> md5Output <- c("d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661", "900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0", "c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f", "57e ..." ... [TRUNCATED]
digest> for (i in seq(along = md5Input)) {
md5 <- digest(md5Input[i], serialize = FALSE)
stopifnot(identical(md5, md5Output[i]))
}
digest> sha1Input <- c("abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
NULL)
digest> sha1Output <- c("a9993e364706816aba3e25717850c26c9cd0d89d",
"84983e441c3bd26ebaae4aa1f95129e5e54670f1", "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
digest> for (i in seq(along = sha1Input)) {
sha1 <- digest(sha1Input[i], algo = "sha1", serialize = FALSE)
stopifnot(identical(sha1, sha1Output[i]))
}
digest> crc32Input <- c("abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
NULL)
digest> crc32Output <- c("352441c2", "171a3f5f", "2ef80172")
digest> for (i in seq(along = crc32Input)) {
crc32 <- digest(crc32Input[i], algo = "crc32", serialize = FALSE)
stopifnot(identical(crc32, crc32Output[i]))
}
digest> sha1 <- digest("abc", algo = "sha1", serialize = FALSE)
digest> stopifnot(identical(sha1, "a9993e364706816aba3e25717850c26c9cd0d89d"))
digest> digest(list(LETTERS, data.frame(a = letters[1:5],
b = matrix(1:10, ncol = 2))))
[1] "20f8c37b7860c9d7c4aff15ab254e054"
digest> fname = file.path(R.home(), "COPYING")
digest> x = readChar(fname, file.info(fname)$size)
digest> for (alg in c("sha1", "md5", "crc32")) {
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, se .... [TRUNCATED]
digest> library(tools)
digest> fname = file.path(R.home(), "COPYING")
digest> h1 = as.character(md5sum(fname))
digest> h2 = digest(fname, algo = "md5", file = TRUE)
digest> stopifnot(identical(h1, h2))
>
DownloadFrom this machine, you can get the digest most recent tar archive, or simply peruse the entire directory.Alternatively, you can also get digest from a Comprehensive R Archive Network (CRAN) node in the src/contrib directory, or visit the project archive (including access to the Subversion repository) at the R-Forge host.
InstallationThe easiest way is probably to simply sayinstall.package("digest") from inside GNU R. Alternatively, R CMD
INSTALL digest_*.tar.gz will install from command prompt.
|
|||||