Web3 Voice🎙
import hashlib
# Alice's set of data
alice_set = [(1, 2), (3, 4), (5, 6)]
# Bob's set of data
bob_set = [(2, 3), (4, 5), (6, 7)]
# Alice's hash function
def hash_alice(data):
# Use SHA-256 as the hash function
h = hashlib.sha256()
h.update(str(data).encode())
return h.hexdigest()
# Bob's hash function
def hash_bob(data):
# Use SHA-256 as the hash function
h = hashlib.sha256()
h.update(str(data).encode())
return h.hexdigest()
# Generate a random number for Alice and Bob
alice_random = 12345
bob_random = 67890
# Hash each element in Alice's set using Alice's hash function and the random number
alice_hashes = [hash_alice((data, alice_random)) for data in alice_set]
# Hash each element in Bob's set using Bob's hash function and the random number
bob_hashes = [hash_bob((data, bob_random)) for data in bob_set]
# Exchange the hashes
received_alice = bob_hashes
received_bob = alice_hashes
# Compute the intersection by comparing the received hashes
intersection = []
for h1 in received_alice:
for h2 in received_bob:
if h1 == h2:
intersection.append(h1)
print(f"Intersection: {intersection}")
In this script, Alice and Bob each have a set of data and a hash function that takes an element of the set and a random number as input and returns a hash. They exchange the hashes of their sets and compare them to find the intersection.import hashlib
# Alice's set of data
alice_set = [(1, 2), (3, 4), (5, 6)]
# Bob's set of data
bob_set = [(1, 2), (4, 5), (6, 7)]
# Alice's hash function
def hash_alice(data):
# Use SHA-256 as the hash function
h = hashlib.sha256()
h.update(str(data).encode())
return h.hexdigest()
# Bob's hash function
def hash_bob(data):
# Use SHA-256 as the hash function
h = hashlib.sha256()
h.update(str(data).encode())
return h.hexdigest()
# Generate a random number for Alice and Bob
alice_random = 12345
bob_random = 67890
# Hash each element in Alice's set using Alice's hash function and the random number
alice_hashes = [hash_alice((data, alice_random)) for data in alice_set]
# Hash each element in Bob's set using Bob's hash function and the random number
bob_hashes = [hash_bob((data, bob_random)) for data in bob_set]
# Exchange the hashes
received_alice = bob_hashes
received_bob = alice_hashes
# Compute the intersection by comparing the received hashes
intersection = []
for h1 in received_alice:
for h2 in received_bob:
if h1 == h2:
intersection.append(h1)
print(f"Intersection: {intersection}")
In this script, Alice's and Bob's sets now have an element in common: (1, 2). Running the script should print the intersection of the two sets, which in this case should be a list containing the hash of the element (1, 2).import hashlib
# Alice's set of data
alice_set = [(1, 2), (3, 4), (5, 6)]
# Bob's set of data
bob_set = [(1, 2), (4, 5), (6, 7)]
# Alice's hash function
def hash_alice(data):
# Use SHA-256 as the hash function
h = hashlib.sha256()
h.update(str(data).encode())
return h.hexdigest()
# Bob's hash function
def hash_bob(data):
# Use SHA-256 as the hash function
h = hashlib.sha256()
h.update(str(data).encode())
return h.hexdigest()
# Generate a random number for Alice and Bob
random_number = 12345
# Hash each element in Alice's set using Alice's hash function and the random number
alice_hashes = [hash_alice((data, random_number)) for data in alice_set]
# Hash each element in Bob's set using Bob's hash function and the random number
bob_hashes = [hash_bob((data, random_number)) for data in bob_set]
# Exchange the hashes
received_alice = bob_hashes
received_bob = alice_hashes
# Compute the intersection by comparing the received hashes
intersection = []
for h1 in received_alice:
for h2 in received_bob:
if h1 == h2:
intersection.append(h1)
print(f"Intersection: {intersection}")
Running this modified script should now yield the correct intersection of the two sets:Intersection: ['04fdf706fd632db6a99050095af9aae927af611019630567b9360a3fd6e073aa']It is important to note that in practice, Alice and Bob would not be able to compute the intersection of their sets by simply comparing the hashes. To do that, they would need to use additional cryptographic techniques such as multiparty computation or homomorphic encryption. However, these techniques are beyond the scope of this answer.
0x91731A5eDD443a6cfdFEcD543cD1aCdad1F83c5E. После, я сгенерировал следующую картинку, введя мнемоник в Midjourney. Тот, кто первый разгадает все 12 слов мнемоника, имеет полное право забрать себе эти 0.5 ETH. Путь генерации стандартный — m/44'/60'/0'/0/0.const nacl = require('tweetnacl')
function toHex(buf) {
return Buffer.from(buf).toString('hex')
}
function toBuffer(hex) {
return Uint8Array.from(Buffer.from(hex, 'hex'))
}
// Encrypt the sets using the public keys of the other party
function encrypted(set, secretKey, otherPartyPK, nonce) {
const enc = new TextEncoder()
return set.map((item) =>
toHex(nacl.box(enc.encode(item), nonce, otherPartyPK, secretKey))
)
}
function PSI(secretKey, otherPartyPK, setA, setB, nonce) {
// Intersect the encrypted sets by comparing their elements
const intersection = setA.filter((item) => setB.includes(item))
// Decrypt the intersection using the private key of the other party
const decryptedIntersection = intersection.map((item) =>
nacl.box.open(toBuffer(item), nonce, otherPartyPK, secretKey)
)
// Return the decrypted intersection as an array of strings
const dec = new TextDecoder()
return decryptedIntersection.map((item) => dec.decode(item))
}
// Generate a fixed nonce
const nonce = nacl.randomBytes(nacl.box.nonceLength)
// Generate a new set of keys for Alice
const aliceKey = nacl.box.keyPair()
// Generate a new set of keys for Bob
const bobKey = nacl.box.keyPair()
// Alice's set
const aliceSet = ['(1,1)', '(2,2)', '(3,3)']
const aliceSetEncrypted = encrypted(
aliceSet,
aliceKey.secretKey,
bobKey.publicKey,
nonce
)
console.log('aliceSetEncrypted', aliceSetEncrypted)
// Bob's set
const bobSet = ['(3,1)', '(2,2)', '(1,3)']
const bobSetEncrypted = encrypted(
bobSet,
bobKey.secretKey,
aliceKey.publicKey,
nonce
)
console.log('bobSetEncrypted', bobSetEncrypted)
// Alice computes the intersection of her set with Bob's set
const intersection = PSI(
aliceKey.secretKey,
bobKey.publicKey,
aliceSetEncrypted,
bobSetEncrypted,
nonce
)
console.log('the intersection', intersection)
outaliceSetEncrypted [
'4919b90208e5321e8a50aa13df5ddc737b114fe66b',
'7f7d0db0b0c7a3421a10beddcfbbded27b124fe56b',
'b5e1615d59aa1467aacfd1a7c019e1317b134fe46b'
]
bobSetEncrypted [
'62297c6d1c152997a048e89ffea5007a7b134fe66b',
'7f7d0db0b0c7a3421a10beddcfbbded27b124fe56b',
'9cd19ef2447a1eee93d7931ba1d1bc2b7b114fe46b'
]
the intersection [ '(2,2)' ]
'7f7d0db0b0c7a3421a10beddcfbbded27b124fe56b'
получен разными секретамиf('(2,2)', aliceKey.secretKey, bobKey.publicKey, nonce)
f('(2,2)', bobKey.secretKey, aliceKey.publicKey, nonce)
(0,1)---(1,1)In this example, each node is connected to four other nodes. We can represent the connections between nodes using an adjacency matrix:
| |
(0,0)---(1,0)
(0,1) (1,1)To route a message from node (0,0) to node (1,1), we can follow the following steps:
(0,0) 0 1
1 0 0
(1,0)
{
value 16 u< if
// число меньше 128, записываем его как есть
8 u,
else
// число больше или равно 128, записываем первые два байта равные 128, а третий байт равный value - 128
128 16 u, value 128 - 16 u,
then
}
---------------------------------------------------------------
|Library | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|
|---------------+---+---+---+---+---+---+---+---+---+---+---+---|
|Everscale-SDK | V | V | V | V | X | X | X | X | X | X | X | V |
replit.com/@ilyar/Everscale-ed25519-speccheck#index.js
operator fun BigInteger.times(value: Int) = times(value.toBigInteger())
Отныне и навек звать тебя 🔲Суперквадрат