from typing import Union
from typing import Tuple
import secrets
import hashlib


def wep_encypher_pw(password: str, salt: Union[None, str] = None) -> Tuple[str, str]:
    """
    Hash and salt a password string and return the SHA-512 digest of the
    hashed and salted string.
    Args:
        password: A password inputted by the user
        salt: The salt to apply to the password before hashing

    Returns:
        The SHA-512 message digest, in hexadecimal form, of the password
        string with a salt applied, along with the salt itself.
    """
    if not salt:
        salt = secrets.token_hex(16)
    return salt, hashlib.sha512((password + salt).encode("utf-8")).hexdigest()