我想知道如何将 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/