如何将 512 位字符串转换为特定的 256 位字符串 [已关闭]

问题描述 投票:0回答:1

让:

A= 7d76d950bbab4cb47a190c2258b7265a5e85b14ae4d8828215c5d83069b924f18b6b31eb0fb413130b9a37e899057930b0a567fe7641f1ca3e77b09db7ee6154
B= 6930d87b298f352e024314695578e4b9a0fca8d721756846e15b771021b68842da2fac27c8846e766d9ff91ca094ed9c80901141a7b7329bfe43270d0091acfa
C= 8f4a8f4bf7c53e1db32a36b916b37737ecf88b464cf487e641442c3d8b31ebed3b1b59d18be36d5b2ea8ccd1656b251d1870a01c90375b15286775e00608af1f
D= 6688680364e5b1487fd787cc53aca63049fe972992516839a06a70a5d206e2eda4ab334ee58299fe4c0b0e9093b87c9e103162fc7c28c638090f0ff41c47a81b

从上面的任何一个选项中,是否可以仅使用其中一个来获得这个精确的 256 位十六进制字符串

faf85c499169106738965e726b3a7eb29189c1b9f2139359a36971fc184e6099

就像数学计算一样,当我将其中任何一个(仅一个)输入到 python 脚本中时,它会输出精确的 256 位十六进制字符串,它不能对所有字符串都起作用,只是其中任何一个都可以,这是我正在解决的一部分学校项目我希望我能得到一个Python脚本来完成我解释的事情谢谢

我尝试为此创建一个Python脚本,但没有成功

python math cryptography sha256 sha512
1个回答
0
投票
import hashlib

# Choose one of your input strings (e.g., A)
input_string = "7d76d950bbab4cb47a190c2258b7265a5e85b14ae4d8828215c5d83069b924f18b6b31eb0fb413130b9a37e899057930b0a567fe7641f1ca3e77b09db7ee6154"

# Convert the input string from hexadecimal to bytes
input_bytes = bytes.fromhex(input_string)

# Calculate the SHA-256 hash
hash_result = hashlib.sha256(input_bytes).hexdigest()

# Print the 256-bit hex string
print(hash_result)

© www.soinside.com 2019 - 2024. All rights reserved.