當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。