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


Python binascii.hexlify方法代码示例

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


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

示例1: render

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def render(self):
        while self.ts.run:
            while self.ts.pause:
                self.checkkey()
                time.sleep(.1)

            (self.maxy,self.maxx) = self.stdscr.getmaxyx()

            self.sx = 1
            self.sy = max((self.maxy + 1 - (self.T.IL + self.T.UL + 5 + 2))/2, 0)

            self.checkkey()

            synth_insn = cstr2py(self.T.r.raw_insn)

            if synth_insn and not self.ts.pause:
                self.draw()

            if self.do_tick:
                self.ticks = self.ticks + 1
                if self.ticks & self.TICK_MASK == 0:
                    with open(TICK, 'w') as f:
                        f.write("%s" % hexlify(synth_insn))

            time.sleep(self.TIME_SLICE) 
开发者ID:Battelle,项目名称:sandsifter,代码行数:27,代码来源:sifter.py

示例2: x

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def x(self):
    """ Get data from BMS board"""
    command = bytes.fromhex('DD A5 03 00 FF FD 77')
    dat = self.getbmsdat(self.ser,command)
    self.rawi[0] = int.from_bytes(dat[2:4], byteorder = 'big',signed=True)
#    print (self.rawi)
#    self.line1 = [ 0 for i in range(int(len(dat)))]
#    for i in range(0,int(len(dat))):
  #    print (dat[i*2:i*2+2])
  #    print (int.from_bytes(dat[i:i+1], byteorder = 'big'))
#      self.line1[i] = int.from_bytes(dat[i:i+1], byteorder = 'big')
#    print (binascii.hexlify(dat))
#    print (self.line1)


  # voltages
    command = bytes.fromhex('DD A5 04 00 FF FC 77')
    voltages = self.getbmsdat(self.ser,command)
    for i in range(0,numcells):
      self.rawv[i+1] = int.from_bytes(voltages[i*2:i*2+2], byteorder = 'big')\
                       /1000.00
      self.rawv[i+1] = self.rawv[i+1]+self.rawv[i]
  #  print (self.rawv)
  #  print (binascii.hexlify(voltages)) 
开发者ID:simat,项目名称:BatteryMonitor,代码行数:26,代码来源:getbms.py

示例3: get

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def get(self, file_id: str) -> None:  # type: ignore
        """Get a file from the database and show it in hex."""

        with database.session() as session:
            file = (
                session.query(database.File)
                .filter(database.File.slug == file_id)
                .first()
            )

            if not file:
                raise tornado.web.HTTPError(404)

            if file.paste.exp_date < datetime.now():
                session.delete(file.paste)
                session.commit()

                log.warn(
                    "FileRaw.get: paste was expired, is your cronjob running?"
                )

                raise tornado.web.HTTPError(404)

            self.set_header("Content-Type", "text/plain; charset=utf-8")
            self.write(binascii.hexlify(file.raw.encode("latin1"))) 
开发者ID:supakeen,项目名称:pinnwand,代码行数:27,代码来源:website.py

示例4: message

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def message(self):
        error_details_msg = ""
        for error_detail in self.error_details:
            if isinstance(error_detail, SMB2SymbolicLinkErrorResponse):
                detail_msg = self._get_symlink_error_detail_msg(error_detail)
            elif isinstance(error_detail, SMB2ShareRedirectErrorContext):
                detail_msg = self._get_share_redirect_detail_msg(error_detail)
            else:
                # unknown error details in response, output raw bytes
                detail_msg = "Raw: %s" % binascii.hexlify(error_detail).decode('utf-8')

            # the first details message is set differently
            if error_details_msg == "":
                error_details_msg = "%s - %s" % (error_details_msg, detail_msg)
            else:
                error_details_msg = "%s, %s" % (error_details_msg, detail_msg)

        status_hex = format(self.status, 'x')
        error_message = "%s: 0x%s%s" % (str(self.header['status']),
                                        status_hex, error_details_msg)
        return "Received unexpected status from the server: %s" % error_message 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:23,代码来源:exceptions.py

示例5: switchfets

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def switchfets(port='/dev/ttyUSB0'):
  """ switch charge and discharge fets """
  print ('(03)=Both FETs off')
  print ('(01)=Discharge FET on, Charge FET off')
  print ('(02)=Discharge FET off, Charge FET on')
  print ('(00)=Both FETs on')
  usercmd = input("Enter numeric option> ")
  ser = bmscore.openbms(port)
  command = bytes.fromhex('DD A5 03 00 FF FD 77')
  print ('command=',binascii.hexlify(command))
  data=bmscore.getbmsdat(ser,command)
  print ('reply=',binascii.hexlify(data))
  command = bytes.fromhex('DD A5 04 00 FF FC 77')
  print ('command=',binascii.hexlify(command))
  data=bmscore.getbmsdat(ser,command)
  print ('reply=',binascii.hexlify(data))
  command = bytes.fromhex('DD 5A 00 02 56 78 FF 30 77')
  data=bmscore.getbmsdat(ser,command)
  print ('reply=',binascii.hexlify(data))
  usercmd=b'\xE1\x02\x00'+bytes.fromhex(usercmd)
  command = b'\xDD\x5A'+usercmd+bmscore.crccalc(usercmd).to_bytes(2, byteorder='big')+b'\x77'
  print (binascii.hexlify(command))
  bmscore.getbmsdat(ser,command)
  command = bytes.fromhex('DD 5A 01 02 00 00 FF FD 77')
  bmscore.getbmsdat(ser,command) 
开发者ID:simat,项目名称:BatteryMonitor,代码行数:27,代码来源:bmstest.py

示例6: _bytes_representation

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def _bytes_representation(data):
    """
    Converts a bytestring into something that is safe to print on all Python
    platforms.

    This function is relatively expensive, so it should not be called on the
    mainline of the code. It's safe to use in things like object repr methods
    though.
    """
    if data is None:
        return None

    hex = binascii.hexlify(data)

    # This is moderately clever: on all Python versions hexlify returns a byte
    # string. On Python 3 we want an actual string, so we just check whether
    # that's what we have.
    if not isinstance(hex, str):  # pragma: no cover
        hex = hex.decode('ascii')

    return hex 
开发者ID:python-hyper,项目名称:hyper-h2,代码行数:23,代码来源:events.py

示例7: assert_fingerprint

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def assert_fingerprint(cert, fingerprint):
    """
    Checks if given fingerprint matches the supplied certificate.

    :param cert:
        Certificate as bytes object.
    :param fingerprint:
        Fingerprint as string of hexdigits, can be interspersed by colons.
    """

    fingerprint = fingerprint.replace(':', '').lower()
    digest_length = len(fingerprint)
    hashfunc = HASHFUNC_MAP.get(digest_length)
    if not hashfunc:
        raise SSLError(
            'Fingerprint of invalid length: {0}'.format(fingerprint))

    # We need encode() here for py32; works on py2 and p33.
    fingerprint_bytes = unhexlify(fingerprint.encode())

    cert_digest = hashfunc(cert).digest()

    if not _const_compare_digest(cert_digest, fingerprint_bytes):
        raise SSLError('Fingerprints did not match. Expected "{0}", got "{1}".'
                       .format(fingerprint, hexlify(cert_digest))) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:27,代码来源:ssl_.py

示例8: with_payment_id

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [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

示例9: get_md5_hash

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def get_md5_hash(self, enc_hex, key):
        # convert hash from hex to binary
        enc_binary = binascii.unhexlify(enc_hex)

        # retrieve the salt
        salt = hashlib.sha1('\x00\x00\x00\x00' + key).digest() + hashlib.sha1('\x00\x00\x00\x01' + key).digest()

        # encrypt value used with the XOR operation
        aes_key = self.aes_encrypt(struct.pack('I', 0) * 4, salt[0:32])[0:16]

        # XOR operation
        decrypted = []
        for d in range(16):
            decrypted.append(struct.unpack('B', enc_binary[d])[0] ^ struct.unpack('B', aes_key[d])[0])

        # cast the result byte
        tmp = ''
        for dec in decrypted:
            tmp = tmp + struct.pack(">I", dec).strip('\x00')

        # byte to hex
        return binascii.hexlify(tmp)

    # used for dictionary attack, if user specify a specific file 
开发者ID:mehulj94,项目名称:Radium,代码行数:26,代码来源:skype.py

示例10: _dump_additional_attributes

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def _dump_additional_attributes(additional_attributes):
    """ try to parse additional attributes, but ends up to hexdump if the scheme is unknown """

    attributes_raw = io.BytesIO(additional_attributes)
    attributes_hex = binascii.hexlify(additional_attributes)

    if not len(additional_attributes):
        return attributes_hex

    len_attribute, = unpack('<I', attributes_raw.read(4))
    if len_attribute != 8:
        return attributes_hex

    attr_id, = unpack('<I', attributes_raw.read(4))
    if attr_id != APK._APK_SIG_ATTR_V2_STRIPPING_PROTECTION:
        return attributes_hex
        
    scheme_id, = unpack('<I', attributes_raw.read(4))

    return "stripping protection set, scheme %d" % scheme_id 
开发者ID:amimo,项目名称:dcc,代码行数:22,代码来源:apk.py

示例11: get_distrust_timeline

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def get_distrust_timeline(
        cls, verified_certificate_chain: List[Certificate]
    ) -> Optional[SymantecDistrustTimelineEnum]:
        has_whitelisted_cert = False
        has_blacklisted_cert = False

        # Is there a Symantec root certificate in the chain?
        for certificate in verified_certificate_chain:
            key_hash = binascii.hexlify(get_public_key_sha256(certificate)).decode("ascii")
            if key_hash in cls._CA_KEYS_BLACKLIST:
                has_blacklisted_cert = True
            if key_hash in cls._CA_KEYS_WHITELIST:
                has_whitelisted_cert = True

        distrust_enum = None
        if has_blacklisted_cert and not has_whitelisted_cert:
            leaf_cert = verified_certificate_chain[0]
            if leaf_cert.not_valid_before < datetime(year=2016, month=6, day=1):
                distrust_enum = SymantecDistrustTimelineEnum.MARCH_2018
            else:
                distrust_enum = SymantecDistrustTimelineEnum.SEPTEMBER_2018
        return distrust_enum 
开发者ID:nabla-c0d3,项目名称:sslyze,代码行数:24,代码来源:_symantec.py

示例12: _convert_hexstring

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def _convert_hexstring(input_spec,
                       output_spec,
                       output_codec,
                       type_name,
                       hexstring):
    try:
        encoded = binascii.unhexlify(hexstring)
    except Exception as e:
        raise TypeError("'{}': {}".format(hexstring, str(e)))

    decoded = input_spec.decode(type_name, encoded)

    if output_codec in ['gser', 'xer', 'jer']:
        decoded = output_spec.encode(type_name, decoded, indent=4).strip()
    else:
        decoded = binascii.hexlify(output_spec.encode(type_name, decoded))

    print(decoded.decode('latin-1')) 
开发者ID:eerimoq,项目名称:asn1tools,代码行数:20,代码来源:__init__.py

示例13: key_fingerprint

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def key_fingerprint(key):
    hex_fp = binascii.hexlify(key.get_fingerprint()).decode()
    return key.get_name() + " " + ":".join(hex_fp[i:i + 2] for i in range(0, len(hex_fp), 2)) 
开发者ID:kislyuk,项目名称:aegea,代码行数:5,代码来源:crypto.py

示例14: __str__

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def __str__(self):
        return hexlify(self.token) 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:4,代码来源:clamav.py

示例15: _function_get_json

# 需要导入模块: import binascii [as 别名]
# 或者: from binascii import hexlify [as 别名]
def _function_get_json(func):
    """Return the function in standalone JSON"""
    data = dict(func.data)
    data["chunks"] = []
    for chunk in func.chunks:
        c = dict(chunk.data)
        c["bytes"] = binascii.hexlify(chunk.bytes)
        data["chunks"].append(c)

    return data 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:12,代码来源:server.py


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