SB1 on Nostr: Here the py ``` import hashlib import bech32 # Read the file data with open(filename, ...
Here the py
```
import hashlib
import bech32
# Read the file data
with open(filename, 'rb') as f:
data = f.read()
# Calculate the SHA-256 hash of the file data
hash = hashlib.sha256(data).hexdigest()
# Serialize the list of Bech32-encoded public keys
serialized_names = []
for name in names:
# Convert the key to bytes
key_bytes = bech32.decode(name)
# Append the key to the list of serialized names
serialized_names.append(key_bytes)
# Concatenate the inputs and the serialized names with the file data
concatenated_data = bytes.fromhex(A) + data + b''.join(serialized_names)
# Calculate the SHA-256 hash of the concatenated data
final_hash = hashlib.sha256(concatenated_data).hexdigest()
# Compare the final hash with the Result
proof = final_hash == Result
# Calculate the n-times hashed final hash
n_times_hashed = final_hash
for i in range(n):
n_times_hashed = hashlib.sha256(bytes.fromhex(n_times_hashed)).hexdigest()
# Output the hashes
print("Data Hash:", hash)
print("Final Hash:", final_hash)
print("Proof:", proof)
print(f"{n} times hashed final hash: {n_times_hashed}")
```
Published at
2023-01-18 15:56:32Event JSON
{
"id": "45abc025102f335ba4b8d029cb6e305fbf10b533dc9eb690efb74ed4662d4e19",
"pubkey": "1ce88359c56de5a35cea9413d1b98bc8ed3e8362c02469beab6064fd8d6e8eae",
"created_at": 1674057392,
"kind": 1,
"tags": [
[
"e",
"ec6127115e6363f0cec9e7426708a978ae08af5c7ab9dc0cbcb1da1bce02c2ff",
"wss://nostr.ono.re",
"reply"
],
[
"p",
"1ce88359c56de5a35cea9413d1b98bc8ed3e8362c02469beab6064fd8d6e8eae"
],
[
"p",
"d7536260b88cf7e5cc3fca4f82240f342bc098762cf3b855d5d765e78c95ddcb"
],
[
"p",
"eb362a4ad5c55e5ff02ceda83eaab5dbf4e8be07abec25615bb2e3ebbff7bd61",
"wss://relay.nostr.info"
],
[
"p",
"eb362a4ad5c55e5ff02ceda83eaab5dbf4e8be07abec25615bb2e3ebbff7bd61",
"wss://relay.nostr.info"
],
[
"p",
"1ce88359c56de5a35cea9413d1b98bc8ed3e8362c02469beab6064fd8d6e8eae",
"wss://nostr-pub.wellorder.net"
]
],
"content": "Here the py\n```\nimport hashlib\nimport bech32\n\n# Read the file data\nwith open(filename, 'rb') as f:\n data = f.read()\n\n# Calculate the SHA-256 hash of the file data\nhash = hashlib.sha256(data).hexdigest()\n\n# Serialize the list of Bech32-encoded public keys\nserialized_names = []\nfor name in names:\n # Convert the key to bytes\n key_bytes = bech32.decode(name)\n # Append the key to the list of serialized names\n serialized_names.append(key_bytes)\n\n# Concatenate the inputs and the serialized names with the file data\nconcatenated_data = bytes.fromhex(A) + data + b''.join(serialized_names)\n\n# Calculate the SHA-256 hash of the concatenated data\nfinal_hash = hashlib.sha256(concatenated_data).hexdigest()\n\n# Compare the final hash with the Result\nproof = final_hash == Result\n\n# Calculate the n-times hashed final hash\nn_times_hashed = final_hash\nfor i in range(n):\n n_times_hashed = hashlib.sha256(bytes.fromhex(n_times_hashed)).hexdigest()\n\n# Output the hashes\nprint(\"Data Hash:\", hash)\nprint(\"Final Hash:\", final_hash)\nprint(\"Proof:\", proof)\nprint(f\"{n} times hashed final hash: {n_times_hashed}\")\n\n```",
"sig": "812a39d748c6a85101b7b7b77f022169d0900b542d385d959a59fe5344230aec1fc93cb4bcde986c5f80e4411566208561deb10ef34ad4e1eeecf8d4942e3efa"
}