import base64


def b64(content, encode=True):
    """Encode/Decode string to/from base64

    Checks if content is base64 or not. Then converts it to or from base64.

    Args:
        content: Content to encode or decode
        encode: Encode or decode content. Default True (encode string to base64)
    
    Returns:
        The encoded/decoded message
    """

    if encode:
        content_bytes = content.encode('ascii')
        base64_bytes = base64.b64encode(content_bytes)
        base64_content = base64_bytes.decode('ascii')
        return base64_content
    else:
        base64_bytes = content.encode('ascii')
        content_bytes = base64.b64decode(base64_bytes)
        message = content_bytes.decode('ascii')
        return message