我想知道如何将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库。有关更多信息,请参见评论。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句