Beispiel #1
0
    def decode(encoded):
        """
        Decodes a base64 encoded string.

        :param encoded: base64 encoded string
        :param alphabet: alphabet to use in the decoding
        :return: decoded value
        """

        return BaseCodec.decode(encoded, ALPHABET)
Beispiel #2
0
    def encode(value):
        """
        Encodes the given value in base64.

        :param value: value to encode
        :param alphabet: alphabet to use in the encoding
        :return: base64 encoded string
        """

        return BaseCodec.encode(value, ALPHABET, bs=3)
Beispiel #3
0
    def decode(encoded, alphabet=Base62Alphabet.NLU):
        """
        Decodes a base62 encoded string.

        :param encoded: base62 encoded string
        :param alphabet: alphabet to use in the decoding
        :return: decoded value
        """

        if len(alphabet) != 62:
            raise Exception('Invalid alphabet')

        return BaseCodec.decode(encoded, alphabet)
Beispiel #4
0
    def encode(num, alphabet=Base62Alphabet.NLU):
        """
        Encodes the given phrase in base62.

        :param data: value to encode
        :param alphabet: alphabet to use in the encoding
        :return: base62 encoded string
        """

        if len(alphabet) != 62:
            raise Exception('Invalid alphabet')

        return BaseCodec.encode(num, alphabet)