gpt4 book ai didi

Ruby SHA2 摘要不正确的文档或我的 IRB 中的问题?

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:02 25 4
gpt4 key购买 nike

文档@ http://www.ruby-doc.org/stdlib-1.9.3/libdoc/digest/rdoc/Digest/SHA2.html显示:

Digest::SHA256.new.digest_length * 8
#=> 512
Digest::SHA384.new.digest_length * 8
#=> 1024
Digest::SHA512.new.digest_length * 8
#=> 1024

这是我在 2.1.3 中的输出:

Digest::SHA256.new.digest_length * 8
#=> 256
Digest::SHA384.new.digest_length * 8
#=> 384
Digest::SHA512.new.digest_length * 8
#=> 512

为什么我的 block 长度输出与 Ruby 文档不同?

最佳答案

文档好像有错别字,你看,

block_length → Integer
Returns the block length of the digest in bytes.

Digest::SHA256.new.digest_length * 8
# => 512
Digest::SHA384.new.digest_length * 8
# => 1024
Digest::SHA512.new.digest_length * 8
# => 1024

digest_length → Integer
Returns the length of the hash value of the digest in bytes.

Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512

两者都在示例中使用了digest_length

但它应该是,

block_length → Integer
Returns the block length of the digest in bytes.

Digest::SHA256.new.block_length * 8
# => 512
Digest::SHA384.new.block_length * 8
# => 1024
Digest::SHA512.new.block_length * 8
# => 1024

digest_length → Integer
Returns the length of the hash value of the digest in bytes.

Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512

关于Ruby SHA2 摘要不正确的文档或我的 IRB 中的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27084096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com