将摘要转换为 base10
是否可以采用类似创建的摘要
my $digest = Digest::SHA->new('sha1')->add('hello')->digest;
,然后将 $digest
转换为 base10(而不是十六进制或 base64?),或者您可以将十六进制摘要拆分为 5 块 然后将它们转换为整数?那行得通吗?试图想出一种将摘要存储为整数的方法(是的,我知道有人会认为我疯了或愚蠢,可能两者兼而有之)。
更新
理论上,我应该能够获取最终编码的整数输出,并根据需要反转并重新编码为十六进制和 base64。
Is it possible to take a digest created like
my $digest = Digest::SHA->new('sha1')->add('hello')->digest;
and then convert $digest
to base10 (instead of hex or base64?) or could you split a hexdigest into 5 pieces and then convert those into integers? would that work? Trying to come up with a way to store the digest as integers (yes I know someone is going to think I'm crazy or stupid, probably both).
update
In theory I should be able to take the final encoded integer output and reverse and reencode to hex and base64 as needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果无论你要去哪里都可以毫不犹豫地处理任意精度的整数(是的,很奇怪,但你永远不知道),那么你可以将其编码为单个整数;)
If wherever you're going can handle arbitrary-precision integers without flinching (yeah, unikely, but you never know), then you can just encode it as a single integer ;)
我认为
pack
&unpack
可能会更有效:输出:
请注意,
MIME::Base64
会填充结果,而b64digest
方法则不会。但如果需要的话,删除尾随的=
很容易。I think
pack
&unpack
will probably be more efficient:Output:
Note that
MIME::Base64
pads the result, and theb64digest
method doesn't. But it's easy enough to strip off the trailing=
if you need to.也许是这样的?
输出:
Something like this, maybe?
Output: