[英]how can I verify that this hash function is not gonna give me same result for two diiferent strings?
[英]Can I hash two strings into one hash?
我對 Python 很陌生,想創建一些將兩個字符串散列在一起的代碼。 特別是對於我的情況,我想散列文件的散列和比特幣塊散列。 下面的代碼顯然不起作用,因為 sha256() 只接受一個參數。 你們知道嗎?
謝謝,
from __future__ import print_function
import blocktrail, time, csv, hashlib, sys
client = blocktrail.APIClient(api_key="x", api_secret="x", network="BTC", testnet=False)
address = client.address('x')
latest_block = client.block_latest()
hash_list = []
h = latest_block['hash']
sha256 = hashlib.sha256()
BUF_SIZE = 65536
print("test")
with open('entries#x.csv', 'rb') as entriesfile:
buf = entriesfile.read(BUF_SIZE)
while len(buf) > 0:
sha256.update(buf)
buf = entriesfile.read(BUF_SIZE)
print(sha256.hexdigest())
entryhash = sha256.hexdigest()
hashofhe = hashlib.sha256(b'entryhash', 'h')
只是對此發表評論,因為我正在尋找有關同一主題的建議:
"hello", "world"
將具有與"hel", "loworld"
相同的散列。"5hello5world"
和"3hel8loworld"
並且不太可能產生沖突。__hash__
,你可以做hash(hash(a) + hash(b))
。只需連接兩個字符串然后散列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.