def test_correct_hash_function(self): k = keccak_384() print_var_type_n_val(var001=k, pointer="#YTRFGDFGHDFGHFDGH") #YTRFGDFGHDFGHFDGH # Value: # # <_pysha3.keccak_384 object at 0x0000018FAA5536F8> # Type: <class '_pysha3.keccak_384'> # print('k001: ', k) # # <_pysha3.keccak_384 object at 0x0000028B370AF600> k.update('Message'.encode('utf-8')) print_var_type_n_val( var001=k, pointer="#SDFGHytre2345cd345") #SDFGHytre2345cd345 # Value: # # <_pysha3.keccak_384 object at 0x0000018FAA5536F8> # Type: <class '_pysha3.keccak_384'> # print('k_update: ', k) # # <_pysha3.keccak_384 object at 0x0000028B370AF600> self.assertEqual( k.hexdigest(), # <<<<<<<<<<<<<<< '0c8d6ff6e6a1cf18a0d55b20f0bca160d0d1c914a5e842f3' '707a25eeb20a279f6b4e83eda8e43a67697832c7f69f53ca', )
def test_correct_hash_function(): k = sha3.keccak_384() k.update("Message".encode('utf-8')) expected = ('0c8d6ff6e6a1cf18a0d55b20f0bca160d0d1c914a5e842f3' + '707a25eeb20a279f6b4e83eda8e43a67697832c7f69f53ca') assert k.hexdigest() == expected
def test_correct_hash_function(self): k = sha3.keccak_384() k.update("Message".encode('utf-8')) self.assertEqual( k.hexdigest(), "0c8d6ff6e6a1cf18a0d55b20f0bca160d0d1c914a5e842f3707a25eeb20a279f6b4e83eda8e43a67697832c7f69f53ca" )
def test_correct_hash_function(self): k = keccak_384() k.update('Message'.encode('utf-8')) self.assertEqual( k.hexdigest(), '0c8d6ff6e6a1cf18a0d55b20f0bca160d0d1c914a5e842f3' '707a25eeb20a279f6b4e83eda8e43a67697832c7f69f53ca', )
def valid_proof(last_proof, proof, last_hash): """ Validates the Proof, doesn't suffice valid proof verification yet. :param last_proof: <int> Previous Proof :param proof: <int> Current Proof :param last_hash: <str> The hash of the Previous Block :return: <bool> True if correct, False if not. """ guess = f'{last_proof}{proof}{last_hash}'.encode() guess_hash = sha3.keccak_384(guess).hexdigest() return guess_hash[:4] == "0000"
def reset(self): self.k = keccak_384()
def __init__(self): self.k = sha3.keccak_384()
def reset(self): self.k = sha3.keccak_384()
#test Kerl iteration: def H_Kerl(in_trits): k = Kerl() k.absorb(in_trits) out_trits = [] k.squeeze(out_trits) return out_trits def addChecksum(trytes): out = H(trytes) checksum = out[-9:] return trytes+checksum #Test keccak impl. import sha3 k = sha3.keccak_384() k.update("Message") n = k.hexdigest() assert n=="0c8d6ff6e6a1cf18a0d55b20f0bca160d0d1c914a5e842f3707a25eeb20a279f6b4e83eda8e43a67697832c7f69f53ca" ############################ #Test conversions: ############################ value = 10234 trits = Kerl.convertBigintToTrits(value) big = Kerl.convertTritsToBigint(trits) assert big==value value = 13190295509826637194583200125168488859623001289643321872497025844241981297292953903419783680940401133507992851240799 bytes = Kerl.convertBigintToBytes(value)
def reset(self) -> None: self.k = keccak_384()