r - 在 R 中将 md5 哈希转换为 bigint

标签 r hash md5 digest

我想知道如何将 md5 哈希转换为大整数,以便我可以对其应用模运算符。

我使用digest库创建哈希:

h <- digest("luca", algo="md5", ascii=TRUE, raw=TRUE)
> h
[1] 18 0e 41 2e 42 db 5a 8c 45 3c 8a 81 c5 90 4e 5b

我现在想将 h 转换为一个大整数,并能够对其应用模数运算符 (%%)。

我怎样才能做到这一点?

最佳答案

使用 Rmpfr 库1,可以执行以下操作:

# Get a hex string of the MD5 hash:
h = digest("luca", algo="md5", ascii = TRUE, raw = FALSE)
result = mpfr(h, base = 16)
result
# 1 'mpfr' number of precision  128   bits
# [1] 31975486076668374554448903959384968795

result %% 1024
# 1 'mpfr' number of precision  128   bits
# [1] 603

1 要安装 Rmpfr,需要安装其依赖项 GNU mpfr 库。请参阅评论以获取更多信息。

关于r - 在 R 中将 md5 哈希转换为 bigint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651788/

相关文章:

r - 向时间序列图添加垂直线

php - 为什么md5仍然被广泛使用

r - 有效地创建 a x b 扩展网格内存

r - 从 data.frame 中提取仅包含数值的行

r - 将 filter_all(any_vars()) 转换为 filter(across())

ruby - 在 Ruby 中向哈希添加多个项目

C# NTLM 哈希计算器

hash - adler32 哈希的可怕冲突

sql - 从多列创建哈希值

JavaScript MD5 哈希与 Java Applet MD5 哈希?