dawid
dawid

Reputation: 788

How to produce the same MD5 hash in R as in Python?

I have hashes generated in Python this way:

In [2]: from hashlib import md5
   ...: md5(b"some text").hexdigest()
Out[2]: '552e21cd4cd9918678e3c1a0df491bc3'

However, in R, the result is different:

require(digest)
hash = digest("some text", algo="md5")
print(hash)
"bfd22782dabc6d7af9a9af962cc60752"

Upvotes: 2

Views: 154

Answers (1)

dawid
dawid

Reputation: 788

R handles many types of data when hashing. We have to explicitly tell it to not serialize the string:

require(digest)
hash = digest("some text", algo="md5", serialize = FALSE)
print(hash)
"552e21cd4cd9918678e3c1a0df491bc3"

Upvotes: 2

Related Questions