예제 #1
0
def try_hash(task_num, n, hash=b'718CC2121C3E641059BC1C2CFC456111'):
    r0 = os.urandom(6)
    for i in range(n):
        #r = os.urandom(8)
        r = r0 + bytes([i & 0xFF, i & 0xFF00 >> 8])
        digest = blake2b_hash(r + hash, digest_size=8)[::-1]

        #digest = blake2b(r+hash, digest_size=8).digest()[::-1]

        if digest >= bytes.fromhex('ffffffc000000000'):
            print(f'task {task_num}: found it {digest.hex()}')
            return digest
    #print(f'task {task_num}: done')
    return None
예제 #2
0
def public_key_to_account(public_key: bytes) -> str:
    hash = blake2b_hash(public_key, digest_size=5)

    num = int.from_bytes(public_key, byteorder="big")
    num = num << 40
    num = num | int.from_bytes(hash, byteorder="little")

    output = ""
    for i in range(60):
        r = num & 0x1F
        num = num >> 5
        output += account_encode(r)

    output += "_onan"
    return output[::-1]
예제 #3
0
def account_to_public_key(account: str) -> bytes:
    assert account.startswith('xrb_')
    num = 0
    for c in account[4:]:
        # c = ord(c)
        # assert c >= 0x30
        # assert c < 0x80
        byte = account_decode(c)
        num = num << 5
        num += byte

    public_key = (num >> 40).to_bytes(32, byteorder="big")
    sent_hash = (num & 0xffffffffff).to_bytes(5, byteorder="little")
    pk_hash = blake2b_hash(public_key, digest_size=5)
    assert sent_hash == pk_hash, "checksum incorrect"

    return public_key
예제 #4
0
 def hash_sync(self):
     return blake2b_hash(self.previous + self.destination + self.balance)
예제 #5
0
def sync_benchmark_blake2b(n):
    for i in range(n):
        blake2b_hash(hashable)
예제 #6
0
 def hash_sync(self):
     return blake2b_hash(self.previous + self.source)
예제 #7
0
def deterministic_key(seed: bytes, index: int):
    private_key = blake2b_hash(seed + index.to_bytes(4, byteorder="big"),
                               digest_size=32)
    public_key = SigningKey(private_key).get_verifying_key().to_bytes()
    return private_key, public_key
예제 #8
0
 def hash_sync(self):
     return blake2b_hash(self.previous + self.representative)
예제 #9
0
 def hash_sync(self):
     return blake2b_hash(self.source + self.representative + self.account)
예제 #10
0
        print((time.time() - s) * 1000)
        for t in tasks:
            print(t.result())
            if t.result():
                found = True
                print('FOUND', t.result())
                print((time.time() - s0) * 1000)


if __name__ == '__main__':
    s = time.process_time()
    for i in range(100000000):
        # h = blake2b()
        # h.update(b'718CC2121C3E641059BC1C2CFC456111')
        # h.update(r)
        # h.hexdigest()

        s2 = time.process_time()
        r = os.urandom(8)
        # print((time.process_time() - s2)*1000)
        digest = blake2b_hash(r,
                              b'718CC2121C3E641059BC1C2CFC456111',
                              digest_size=8)[::-1]
        # print((time.process_time() - s2)*1000)
        # print("#")
        if digest >= bytes.fromhex('ffffffc000000000'):
            print('found it')
            print(digest)
            break

    print((time.process_time() - s) * 1000)