def sha3(*args): data = "" for i in args: if isinstance(i, (int, long)): data += encode(i, 256, 32) if isinstance(i, (list, tuple)): data += "".join(encode(j, 256, 32) for j in i) if isinstance(i, str): data += i result = decode(_sha3(data).digest(), 256) if result > 2 ** 255: result -= 2 ** 256 return result
def sha3(*args): data = '' for i in args: if isinstance(i, (int, long)): data += encode(i, 256, 32) if isinstance(i, (list, tuple)): data += ''.join(encode(j, 256, 32) for j in i) if isinstance(i, str): data += i result = decode(_sha3(data).digest(), 256) if result > 2**255: result -= 2**256 return result
def sha3(r): return _sha3(r).digest()
def sha(*args): s = _sha3() for arg in args: s.update(arg) return s.hexdigest()
try: from Crypto.Hash import keccak sha3_256 = lambda x: keccak.new(digest_bits=256, data=x).digest() except: from sha3 import keccak_256 as _sha3 sha3_256 = lambda x: _sha3(x).digest() #from bitcoin import privtopub import sys import rlp from rlp.sedes import big_endian_int, BigEndianInt, Binary from rlp.utils import decode_hex, encode_hex, ascii_chr, str_to_bytes import random big_endian_to_int = lambda x: big_endian_int.deserialize( str_to_bytes(x).lstrip(b'\x00')) int_to_big_endian = lambda x: big_endian_int.serialize(x) TT256 = 2**256 TT256M1 = 2**256 - 1 TT255 = 2**255 if sys.version_info.major == 2: is_numeric = lambda x: isinstance(x, (int, long)) is_string = lambda x: isinstance(x, (str, unicode)) def to_string(value): return str(value) def int_to_bytes(value): if isinstance(value, str): return value