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


Python base64.b16decode方法代码示例

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


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

示例1: _filter_decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def _filter_decode(self, data, encoding):
		if its.py_v3 and isinstance(data, bytes):
			data = data.decode('utf-8')
		encoding = encoding.lower()
		encoding = re.sub(r'^(base|rot)-(\d\d)$', r'\1\2', encoding)

		if encoding == 'base16' or encoding == 'hex':
			data = base64.b16decode(data)
		elif encoding == 'base32':
			data = base64.b32decode(data)
		elif encoding == 'base64':
			data = base64.b64decode(data)
		elif encoding == 'rot13':
			data = codecs.getdecoder('rot-13')(data)[0]
		else:
			raise ValueError('Unknown encoding type: ' + encoding)
		if its.py_v3 and isinstance(data, bytes):
			data = data.decode('utf-8')
		return data 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:21,代码来源:templates.py

示例2: __init__

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def __init__(self, onion_router):
        """:type onion_router: OnionRouter"""
        self._onion_router = onion_router

        # To perform the handshake, the client needs to know an identity key
        # digest for the server, and an NTOR onion key (a curve25519 public
        # key) for that server. Call the NTOR onion key "B".  The client
        # generates a temporary key-pair:
        #     x,X = KEYGEN()
        self._ed25519 = Ed25519()
        self._x = self._ed25519.create_secret_key()
        self._X = self._ed25519.get_public_key(self._x)

        self._B = b64decode(self._onion_router.key_ntor.encode())

        # and generates a client-side handshake with contents:
        #     NODE_ID     Server identity digest  [ID_LENGTH bytes]
        #     KEYID       KEYID(B)                [H_LENGTH bytes]
        #     CLIENT_PK   X                       [G_LENGTH bytes]
        self._handshake = b16decode(self._onion_router.identity.encode())
        self._handshake += self._B
        self._handshake += self._X 
开发者ID:Marten4n6,项目名称:TinyTor,代码行数:24,代码来源:tinytor.py

示例3: test_b16decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def test_b16decode(self):
        eq = self.assertEqual
        eq(base64.b16decode(b'0102ABCDEF'), b'\x01\x02\xab\xcd\xef')
        eq(base64.b16decode('0102ABCDEF'), b'\x01\x02\xab\xcd\xef')
        eq(base64.b16decode(b'00'), b'\x00')
        eq(base64.b16decode('00'), b'\x00')
        # Lower case is not allowed without a flag
        self.assertRaises(binascii.Error, base64.b16decode, b'0102abcdef')
        self.assertRaises(binascii.Error, base64.b16decode, '0102abcdef')
        # Case fold
        eq(base64.b16decode(b'0102abcdef', True), b'\x01\x02\xab\xcd\xef')
        eq(base64.b16decode('0102abcdef', True), b'\x01\x02\xab\xcd\xef')
        # Non-bytes
        self.check_other_types(base64.b16decode, b"0102ABCDEF",
                               b'\x01\x02\xab\xcd\xef')
        self.check_decode_type_errors(base64.b16decode)
        eq(base64.b16decode(bytearray(b"0102abcdef"), True),
           b'\x01\x02\xab\xcd\xef')
        eq(base64.b16decode(memoryview(b"0102abcdef"), True),
           b'\x01\x02\xab\xcd\xef')
        eq(base64.b16decode(array('B', b"0102abcdef"), True),
           b'\x01\x02\xab\xcd\xef') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_base64.py

示例4: Decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def Decode(self, encoded_data):
    """Decode the encoded data.

    Args:
      encoded_data (byte): encoded data.

    Returns:
      tuple(bytes, bytes): decoded data and remaining encoded data.

    Raises:
      BackEndError: if the base16 stream cannot be decoded.
    """
    try:
      decoded_data = base64.b16decode(encoded_data, casefold=False)
    except (TypeError, binascii.Error) as exception:
      raise errors.BackEndError(
          'Unable to decode base16 stream with error: {0!s}.'.format(
              exception))

    return decoded_data, b'' 
开发者ID:log2timeline,项目名称:dfvfs,代码行数:22,代码来源:base16_decoder.py

示例5: b16_slug_to_arguments

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def b16_slug_to_arguments(b16_slug):
    """

        Raises B16DecodingFail exception on
    """
    try:
        url = b16decode(b16_slug.decode('utf-8'))
    except BinaryError:
        raise B16DecodingFail
    except TypeError:
        raise B16DecodingFail('Non-base16 digit found')
    except AttributeError:
        raise B16DecodingFail("b16_slug must have a 'decode' method.")

    try:
        app, model, pk = url.decode('utf-8').split('/')[0:3]
    except UnicodeDecodeError:
        raise B16DecodingFail("Invalid b16_slug passed")
    return app, model, pk 
开发者ID:pydanny,项目名称:dj-spam,代码行数:21,代码来源:utils.py

示例6: decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def decode(self, text):
		try:
			return base64.b16decode(text.upper())
		except:
			return "" 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:7,代码来源:encoding.py

示例7: encrypt

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def encrypt():
    cipher = AES.new(base64.b16decode(key, casefold=True), AES.MODE_ECB)
    return base64.b16encode(cipher.encrypt(flag))


# flush output immediately 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:8,代码来源:ecb.py

示例8: fromhex

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def fromhex(s):
    return base64.b16decode(s.replace(' ', '')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:audiotests.py

示例9: test_b16decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def test_b16decode(self):
        eq = self.assertEqual
        eq(base64.b16decode('0102ABCDEF'), '\x01\x02\xab\xcd\xef')
        eq(base64.b16decode('00'), '\x00')
        # Lower case is not allowed without a flag
        self.assertRaises(TypeError, base64.b16decode, '0102abcdef')
        # Case fold
        eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
        # Non-bytes
        eq(base64.b16decode(bytearray("0102ABCDEF")), '\x01\x02\xab\xcd\xef')
        # Non-alphabet characters
        self.assertRaises(TypeError, base64.b16decode, '0102AG')
        # Incorrect "padding"
        self.assertRaises(TypeError, base64.b16decode, '010') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_base64.py

示例10: _base16_decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def _base16_decode(self, decode_string):
        decoder = base64.b16decode(decode_string, casefol=False)
        return decoder 
开发者ID:agusmakmun,项目名称:Some-Examples-of-Simple-Python-Script,代码行数:5,代码来源:base64_enc_dec.py

示例11: b64from16

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def b64from16(val):
    """ ASCII encoded base 64 string from a base 16 digest """
    return b64from256(b16decode(val, casefold=True)) 
开发者ID:ashleywaite,项目名称:django-more,代码行数:5,代码来源:hashing.py

示例12: test_b16decode

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def test_b16decode(self):
        eq = self.assertEqual
        eq(base64.b16decode('0102ABCDEF'), '\x01\x02\xab\xcd\xef')
        eq(base64.b16decode('00'), '\x00')
        # Lower case is not allowed without a flag
        self.assertRaises(TypeError, base64.b16decode, '0102abcdef')
        # Case fold
        eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
        # Non-bytes
        eq(base64.b16decode(bytearray("0102ABCDEF")), '\x01\x02\xab\xcd\xef') 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:12,代码来源:test_base64.py

示例13: macpack

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def macpack(mac):
    return base64.b16decode(mac.replace(':', '').replace('-', '').encode('ascii')) 
开发者ID:niccokunzmann,项目名称:python_dhcp_server,代码行数:4,代码来源:listener.py

示例14: _to_b32

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def _to_b32(length, value):
    '''
    Convert value to base 32, given that it's supposed to have the same
    length as the digest we're about to compare it to
    '''
    if len(value) == length:
        return value  # casefold needed here? -- rfc recommends not allowing

    if len(value) > length:
        binary = base64.b16decode(value, casefold=True)
    else:
        binary = _b64_wrapper(value)

    return to_native_str(base64.b32encode(binary), encoding='ascii') 
开发者ID:webrecorder,项目名称:warcio,代码行数:16,代码来源:digestverifyingreader.py

示例15: main

# 需要导入模块: import base64 [as 别名]
# 或者: from base64 import b16decode [as 别名]
def main():
    inp = input("->")
    encoded = inp.encode("utf-8")  # encoded the input (we need a bytes like object)
    b16encoded = base64.b16encode(encoded)  # b16encoded the encoded string
    print(b16encoded)
    print(base64.b16decode(b16encoded).decode("utf-8"))  # decoded it 
开发者ID:TheAlgorithms,项目名称:Python,代码行数:8,代码来源:base16.py


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