import six
import hashlib


def hash_digest(*args, salt=None, length=16):
    """ transform the strings in args to a hash hexdigest """

    hash_str = ':'.join(['{}'.format(arg) for arg in args])
    if salt is not None:
        hash_str += str(salt)

    if not isinstance(hash_str, six.binary_type):
        hash_str = hash_str.encode('ascii')

    return hashlib.sha1(hash_str).hexdigest()[:length - 1]