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


Python six.iterbytes方法代码示例

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


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

示例1: gnu_as_mutable_data_finalizer

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def gnu_as_mutable_data_finalizer(get_pc, comment_char, align=True):
    def data_finalizer(env, code, data):
        return (get_pc(env, code) if data or env.buffers else []) + code + [
            '',
            '.pool',
        ] + ([
            '.align',
        ] if align else []) + [
            '__data:',
        ] + [
            '\t.byte %s  %s %r' % (
                ', '.join(hex(b) for b in six.iterbytes(datum)),
                comment_char,
                orig_datum,
            )
            for datum, (_, orig_datum) in six.iteritems(data)
        ]
    return data_finalizer 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:20,代码来源:mutable_data.py

示例2: checksum

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def checksum(msg):
    """
    Calculate CRC-16 (16-bit ISO 13239 1st complement) checksum.
    (see Yubikey-Manual - Chapter 6: Implementation details)

    :param msg: input byte string for crc calculation
    :type msg: bytes
    :return: crc16 checksum of msg
    :rtype: int
    """
    crc = 0xffff
    for b in six.iterbytes(msg):
        crc = crc ^ (b & 0xff)
        for _j in range(0, 8):
            n = crc & 1
            crc = crc >> 1
            if n != 0:
                crc = crc ^ 0x8408
    return crc 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:21,代码来源:__init__.py

示例3: test_protocol_magic_scan_single_byte

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def test_protocol_magic_scan_single_byte(self):
        rx = []

        def cb(packet):
            rx.append(packet)

        protocol_handler = StreamProtocolHandler(MagicSchema, cb)
        test_sequence = MagicSchema()
        test_sequence.value = -29939
        pack = test_sequence.pack()

        # garbage with our bytes in the middle
        test_bytes = b'\x1A\x3fadbsfkasdf;aslkfjasd;f' + pack + b'\x00\x00asdfn234r'
        for b in six.iterbytes(test_bytes):
            protocol_handler.feed(six.b(chr(b)))
        self.assertEqual(len(rx), 1)
        self.assertEqual(rx[0].value, -29939) 
开发者ID:digidotcom,项目名称:python-suitcase,代码行数:19,代码来源:test_protocol.py

示例4: crc24

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def crc24(data):
        # CRC24 computation, as described in the RFC 4880 section on Radix-64 Conversions
        #
        # The checksum is a 24-bit Cyclic Redundancy Check (CRC) converted to
        # four characters of radix-64 encoding by the same MIME base64
        # transformation, preceded by an equal sign (=).  The CRC is computed
        # by using the generator 0x864CFB and an initialization of 0xB704CE.
        # The accumulation is done on the data before it is converted to
        # radix-64, rather than on the converted data.
        crc = Armorable.__crc24_init

        if not isinstance(data, bytearray):
            data = six.iterbytes(data)

        for b in data:
            crc ^= b << 16

            for i in range(8):
                crc <<= 1
                if crc & 0x1000000:
                    crc ^= Armorable.__crc24_poly

        return crc & 0xFFFFFF 
开发者ID:SecurityInnovation,项目名称:PGPy,代码行数:25,代码来源:types.py

示例5: memory

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def memory(ea, op):
        '''Operand type decoder for returning a memory reference on either the AArch32 or AArch64 architectures.'''
        get_dtype_attribute = operator.attrgetter('dtyp' if idaapi.__version__ < 7.0 else 'dtype')
        get_dtype_size = idaapi.get_dtyp_size if idaapi.__version__ < 7.0 else idaapi.get_dtype_size
        get_bytes = idaapi.get_many_bytes if idaapi.__version__ < 7.0 else idaapi.get_bytes

        # get the address and the operand size
        addr, size = op.addr, get_dtype_size(get_dtype_attribute(op))
        maxval = 1<<size*8

        # dereference the address and return its integer.
        res = get_bytes(addr, size) or ''
        res = reversed(res) if database.config.byteorder() == 'little' else iter(res)
        res = reduce(lambda agg, n: (agg*0x100)|n, six.iterbytes(res), 0)
        sf = bool(res & maxval>>1)

        return armops.memory(long(addr), long(res-maxval) if sf else long(res)) 
开发者ID:arizvisa,项目名称:ida-minsc,代码行数:19,代码来源:instruction.py

示例6: _pack_data

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def _pack_data(data):
    return ['__data:'] + [
        '\tdb ' + ','.join(hex(b) for b in six.iterbytes(datum)) + '  ; ' + repr(orig_datum)
        for datum, (_, orig_datum) in six.iteritems(data)
    ] 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:7,代码来源:mutable_data.py

示例7: xor

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def xor(key, data):
    """
    Perform cyclical exclusive or operations on ``data``.

    The ``key`` can be a an integer *(0 <= key < 256)* or a byte sequence. If
    the key is smaller than the provided ``data``, the ``key`` will be
    repeated.

    Args:
        key(int or bytes): The key to xor ``data`` with.
        data(bytes): The data to perform the xor operation on.

    Returns:
        bytes: The result of the exclusive or operation.

    Examples:
        >>> from pwny import *
        >>> xor(5, b'ABCD')
        b'DGFA'
        >>> xor(5, b'DGFA')
        b'ABCD'
        >>> xor(b'pwny', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
        b'15-=51)19=%5=9!)!%=-%!9!)-'
        >>> xor(b'pwny', b'15-=51)19=%5=9!)!%=-%!9!)-')
        b'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    """

    if type(key) is int:
        key = six.int2byte(key)
    key_len = len(key)

    return b''.join(
        six.int2byte(c ^ six.indexbytes(key, i % key_len))
        for i, c in enumerate(six.iterbytes(data))
    ) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:37,代码来源:codec.py

示例8: frequency_app

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def frequency_app(parser, cmd, args):  # pragma: no cover
    """
    perform frequency analysis on a value.
    """

    parser.add_argument('value', help='the value to analyse, read from stdin if omitted', nargs='?')
    args = parser.parse_args(args)
    data = frequency(six.iterbytes(pwnypack.main.binary_value_or_stdin(args.value)))
    return '\n'.join(
        '0x%02x (%c): %d' % (key, chr(key), value)
        if key >= 32 and chr(key) in string.printable else
        '0x%02x ---: %d' % (key, value)
        for key, value in data.items()
    ) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:16,代码来源:codec.py

示例9: _display

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def _display(self, screen, observations, score, elapsed):
    """Redraw the game board onto the screen, with elapsed time and score.

    Args:
      screen: the main, full-screen curses window.
      observations: a list of `rendering.Observation` objects containing
          subwindows of the current game board.
      score: the total return earned by the player, up until now.
      elapsed: a `datetime.timedelta` with the total time the player has spent
          playing this game.
    """
    screen.erase()  # Clear the screen

    # Display the game clock and the current score.
    screen.addstr(0, 2, _format_timedelta(elapsed), curses.color_pair(0))
    screen.addstr(0, 20, 'Score: {}'.format(score), curses.color_pair(0))

    # Display cropped observations side-by-side.
    leftmost_column = 0
    for observation in observations:
      # Display game board rows one-by-one.
      for row, board_line in enumerate(observation.board, start=1):
        screen.move(row, leftmost_column)  # Move to start of this board row.
        # Display game board characters one-by-one. We iterate over them as
        # integer ASCII codepoints for easiest compatibility with python2/3.
        for codepoint in six.iterbytes(board_line.tostring()):
          screen.addch(
              codepoint, curses.color_pair(self._colour_pair[codepoint]))

      # Advance the leftmost column for the next observation.
      leftmost_column += observation.board.shape[1] + 3

    # Redraw the game screen (but in the curses memory buffer only).
    screen.noutrefresh() 
开发者ID:deepmind,项目名称:pycolab,代码行数:36,代码来源:human_ui.py

示例10: _generate_kernel_bin

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def _generate_kernel_bin(self, k, ctx):
        gk = gpuarray.GpuKernel(k.code, k.name, k.params, context=ctx,
                                **k.flags)
        bin = gk._binary
        bcode = ','.join(hex(c) for c in iterbytes(bin))
        return ("""static const char %(bname)s[] = { %(bcode)s };""" %
                dict(bname=k.binvar, bcode=bcode)) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:9,代码来源:basic_ops.py

示例11: _set_next_blob

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def _set_next_blob(data):
    """
    update ``data._obj.Blob``: Increment the contents by 1.
    i.e. "XXX...X" is replaced with "YYY...Y".
    """
    data._obj.Blob = b"".join(six.int2byte(x + 1) for x in six.iterbytes(data._obj.Blob)) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:8,代码来源:test_lib_tokens_vasco.py

示例12: decrypt

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def decrypt(self, str):
        # block - UChar[]
        block = []

        for i in six.iterbytes(str):
            block.append(i)

        # print block
        block = des_ecb_encrypt(block, self.KeySched, 0)

        res = b''
        for i in block:
            res = res + six.int2byte(i)

        return res 
开发者ID:trustrachel,项目名称:python-ntlm3,代码行数:17,代码来源:des_c.py

示例13: str_to_key56

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def str_to_key56(key_str):

    if not type(key_str) == six.binary_type:
        # TODO rsanders high - figure out how to make this not necessary
        key_str = key_str.encode('ascii')

    if len(key_str) < 7:
        key_str = key_str + b'\000\000\000\000\000\000\000'[:(7 - len(key_str))]
    key_56 = []
    for i in six.iterbytes(key_str[:7]):
        key_56.append(i)

    return key_56 
开发者ID:trustrachel,项目名称:python-ntlm3,代码行数:15,代码来源:des.py

示例14: bytes_to_long

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def bytes_to_long(s):
    n = 0
    for b in six.iterbytes(s):
        n = (n << 8) | b
    return n 
开发者ID:mswhirl,项目名称:autoflashgui,代码行数:7,代码来源:mysrp.py

示例15: _serialize_clob

# 需要导入模块: import six [as 别名]
# 或者: from six import iterbytes [as 别名]
def _serialize_clob(ion_event):
    value = ion_event.value
    return _bytes_text(six.iterbytes(value), _DOUBLE_QUOTE, prefix=_LOB_START, suffix=_LOB_END) 
开发者ID:amzn,项目名称:ion-python,代码行数:5,代码来源:writer_text.py


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