当前位置: 首页>>代码示例>>Python>>正文


Python sha3.keccak_256方法代码示例

本文整理汇总了Python中sha3.keccak_256方法的典型用法代码示例。如果您正苦于以下问题:Python sha3.keccak_256方法的具体用法?Python sha3.keccak_256怎么用?Python sha3.keccak_256使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sha3的用法示例。


在下文中一共展示了sha3.keccak_256方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: with_payment_id

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def with_payment_id(self, payment_id=0):
        """Integrates payment id into the address.

        :param payment_id: int, hexadecimal string or :class:`PaymentID <monero.numbers.PaymentID>`
                    (max 64-bit long)

        :rtype: `IntegratedAddress`
        :raises: `TypeError` if the payment id is too long
        """
        payment_id = numbers.PaymentID(payment_id)
        if not payment_id.is_short():
            raise TypeError("Payment ID {0} has more than 64 bits and cannot be integrated".format(payment_id))
        prefix = const.INTADDRR_NETBYTES[const.NETS.index(self.net)]
        data = bytearray([prefix]) + self._decoded[1:65] + struct.pack('>Q', int(payment_id))
        checksum = bytearray(keccak_256(data).digest()[:4])
        return IntegratedAddress(base58.encode(hexlify(data + checksum))) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:18,代码来源:address.py

示例2: public_address

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def public_address(self, net=const.NET_MAIN):
        """Returns the master :class:`Address <monero.address.Address>` represented by the seed.

        :param net: the network, one of `const.NET_*`; default is `const.NET_MAIN`

        :rtype: :class:`Address <monero.address.Address>`
        """
        # backward compatibility
        _net = net[:-3] if net.endswith('net') else net
        if _net != net:
            warnings.warn(
                "Argument '{:s}' is deprecated and will not be accepted in 0.8, "
                "use one of monero.const.NET_*".format(net),
                DeprecationWarning)
            net = _net
        if net not in const.NETS:
            raise ValueError(
                "Invalid net argument '{:s}'. Must be one of monero.const.NET_*".format(net))
        netbyte = (18, 53, 24)[const.NETS.index(net)]
        data = "{:x}{:s}{:s}".format(netbyte, self.public_spend_key(), self.public_view_key())
        h = keccak_256()
        h.update(unhexlify(data))
        checksum = h.hexdigest()
        return address(base58.encode(data + checksum[0:8])) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:26,代码来源:seed.py

示例3: keccak_hash

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def keccak_hash(data, digest_bits=256):
        """
        Create Keccak hash.
        Args:
            data (bytes)
            digest_bits (int)
        Returns:
            hex (string)
        """

        if digest_bits == 256:
            khash = sha3.keccak_256()
        else:
            raise NotImplementedError

        khash.update(data)

        return khash.hexdigest() 
开发者ID:U-node,项目名称:minter-sdk,代码行数:20,代码来源:__init__.py

示例4: _addresses_to_hash160s

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def _addresses_to_hash160s(addresses):
        hash160s = set()
        for address in addresses:
            if address[:2].lower() == "0x":
                address = address[2:]
            if len(address) != 40:
                raise ValueError("length (excluding any '0x' prefix) of Ethereum addresses must be 40")
            cur_hash160 = base64.b16decode(address, casefold=True)
            if not address.islower():  # verify the EIP55 checksum unless all letters are lowercase
                checksum = sha3.keccak_256(base64.b16encode(cur_hash160).lower()).digest()
                for nibble, c in enumerate(address, 0):
                    if c.isalpha() and \
                       c.isupper() != bool(ord(checksum[nibble // 2]) & (0b1000 if nibble&1 else 0b10000000)):
                            raise ValueError("invalid EIP55 checksum")
            hash160s.add(cur_hash160)
        return hash160s 
开发者ID:gurnec,项目名称:btcrecover,代码行数:18,代码来源:btcrseed.py

示例5: symbolic_function

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def symbolic_function(self, func, data):
        """
        Get an unsound symbolication for function `func`

        """
        data = self.try_simplify_to_constant(data)
        try:
            result = []
            self._publish(
                "on_symbolic_function", func, data, result
            )  # This updates the local copy of result

            return result[0]
        except Exception as e:
            logger.info("Error! %r", e)
            data_c = SelectedSolver.instance().get_value(self.constraints, data)
            return int(sha3.keccak_256(data_c).hexdigest(), 16) 
开发者ID:trailofbits,项目名称:manticore,代码行数:19,代码来源:evm.py

示例6: calculate_new_address

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def calculate_new_address(sender=None, nonce=None):
        if sender is None:
            # Just choose a random address for regular accounts:
            new_address = random.randint(100, pow(2, 160))
        elif issymbolic(sender):
            # TODO(Evan Sultanik): In the interim before we come up with a better solution,
            #                      consider breaking Yellow Paper comability and just returning
            #                      a random contract address here
            raise EthereumError(
                "Manticore does not yet support contracts with symbolic addresses creating new contracts"
            )
        else:
            if nonce is None:
                # assume that the sender is a contract account, which is initialized with a nonce of 1
                nonce = 1
            new_address = int(sha3.keccak_256(rlp.encode([sender, nonce])).hexdigest()[24:], 16)
        return new_address 
开发者ID:trailofbits,项目名称:manticore,代码行数:19,代码来源:evm.py

示例7: xmr_verify

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def xmr_verify( xmr_match ):
    try:
        pubAddrHex = monero.base58.decode(xmr_match.decode("utf8"))
        pubAddrChksum = pubAddrHex[-8:]
        pubAddrForHash = pubAddrHex[:-8]
        #print(pubAddrChksum)
        #print(pubAddrForHash)
        k = sha3.keccak_256()
        k.update(unhexlify(pubAddrForHash))
        pubAddrHash = k.hexdigest()
        pubAddrChksum2 = pubAddrHash[:8]
        if pubAddrChksum2 == pubAddrChksum:
            #print("True: %s" % xmr_match)
            return True
        else:
            #print("False: %s" % xmr_match)
            return False
    except Exception as E:
        #print("Exception: %s" % E)
        return False

# Section for regexes of interest as Indicators of Compromise

# URLs 
开发者ID:Concinnity-Risks,项目名称:RansomCoinPublic,代码行数:26,代码来源:coinlector.py

示例8: get_address

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def get_address(self, major, minor):
        """
        Calculates sub-address for account index (`major`) and address index within
        the account (`minor`).

        :rtype: :class:`BaseAddress <monero.address.BaseAddress>`
        """
        # ensure indexes are within uint32
        if major < 0 or major >= 2**32:
            raise ValueError('major index {} is outside uint32 range'.format(major))
        if minor < 0 or minor >= 2**32:
            raise ValueError('minor index {} is outside uint32 range'.format(minor))
        master_address = self.address()
        if major == minor == 0:
            return master_address
        master_svk = unhexlify(self.view_key())
        master_psk = unhexlify(self.address().spend_key())
        # m = Hs("SubAddr\0" || master_svk || major || minor)
        hsdata = b''.join([
                b'SubAddr\0', master_svk,
                struct.pack('<I', major), struct.pack('<I', minor)])
        m = keccak_256(hsdata).digest()
        # D = master_psk + m * B
        D = ed25519.edwards_add(
                ed25519.decodepoint(master_psk),
                ed25519.scalarmult_B(ed25519.decodeint(m)))
        # C = master_svk * D
        C = ed25519.scalarmult(D, ed25519.decodeint(master_svk))
        netbyte = bytearray([const.SUBADDR_NETBYTES[const.NETS.index(master_address.net)]])
        data = netbyte + ed25519.encodepoint(D) + ed25519.encodepoint(C)
        checksum = keccak_256(data).digest()[:4]
        return address.SubAddress(base58.encode(hexlify(data + checksum))) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:34,代码来源:wallet.py

示例9: _decode

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def _decode(self, address):
        self._decoded = bytearray(unhexlify(base58.decode(address)))
        checksum = self._decoded[-4:]
        if checksum != keccak_256(self._decoded[:-4]).digest()[:4]:
            raise ValueError("Invalid checksum in address {}".format(address))
        if self._decoded[0] not in self._valid_netbytes:
            raise ValueError("Invalid address netbyte {nb}. Allowed values are: {allowed}".format(
                nb=self._decoded[0],
                allowed=", ".join(map(lambda b: '%02x' % b, self._valid_netbytes)))) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:11,代码来源:address.py

示例10: base_address

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def base_address(self):
        """Returns the base address without payment id.
        :rtype: :class:`Address`
        """
        prefix = const.MASTERADDR_NETBYTES[const.NETS.index(self.net)]
        data = bytearray([prefix]) + self._decoded[1:65]
        checksum = keccak_256(data).digest()[:4]
        return Address(base58.encode(hexlify(data + checksum))) 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:10,代码来源:address.py

示例11: _hex_seed_keccak

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def _hex_seed_keccak(self):
        h = keccak_256()
        h.update(unhexlify(self.hex))
        return h.digest() 
开发者ID:monero-ecosystem,项目名称:monero-python,代码行数:6,代码来源:seed.py

示例12: hashs

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def hashs(*x):
    data = b''.join(map(tobe256, x))
    return bytes_to_int(keccak_256(data).digest()) 
开发者ID:HarryR,项目名称:solcrypto,代码行数:5,代码来源:utils.py

示例13: pubkey_to_ethaddr

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def pubkey_to_ethaddr(pubkey):
	if isinstance(pubkey, tuple):
		assert len(pubkey) == 2
		pubkey = b.encode_pubkey(pubkey, 'bin')
	return hexlify(keccak_256(pubkey[1:]).digest()[12:]) 
开发者ID:HarryR,项目名称:solcrypto,代码行数:7,代码来源:ecdsa.py

示例14: keccak_256

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def keccak_256(value):
        return keccak.new(digest_bits=256, data=value).digest() 
开发者ID:carlosfaria94,项目名称:blocksim,代码行数:4,代码来源:utils.py

示例15: get_function_id

# 需要导入模块: import sha3 [as 别名]
# 或者: from sha3 import keccak_256 [as 别名]
def get_function_id(sig):
    ''''
        Return the function id of the given signature
    Args:
        sig (str)
    Return:
        (int)
    '''
    s = sha3.keccak_256()
    s.update(sig.encode('utf-8'))
    return int("0x" + s.hexdigest()[:8], 16) 
开发者ID:crytic,项目名称:slither,代码行数:13,代码来源:function.py


注:本文中的sha3.keccak_256方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。