
    ןEf                     (    d dl Z dZdZd ZdefdZdS )    N0123456789abcdefz@0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_c                     | dk    r|d         S t          |          }d}| r"||t          | |z                     z  }| |z  } | "|ddd         S )aj  Encode integer into string, using digit encoding table.

    You can encode integer into hexadecimal string:

    >>> int_to_enc(20190925, enc_table_16)
    '13416cd'

    To verify use, python's hex() function:

    >>> hex(20190925)
    '0x13416cd'

    You can encode integer using 64 digit table:

    >>> int_to_enc(20190925, enc_table_64)
    '1d1rd'

    r    N)lenint)n	enc_tablebasedigitss       ./cmf/util/cmf_hashlib.py
int_to_encr      sm    & 	Avv|y>>DF
 )CDMM**	d
   $$B$<       c                    |dk    r"t          d                    |                    t          j        |                                           }|                                }t          t          |d          |          }|d|         S )a  Geneate string hash with given length, using specified encoding table.

    Example 1:

    Generating hash with length of 8 characters, using hexadecimal encoding table:

    >>> short_str_enc("hello world", 8, enc_table_16)
    '309ecc48'

    Generating hash with length of 8 charactes, using extended 64-digit encoding table:

    >>> short_str_enc("hello world", 8, enc_table_64)
    'MDIN8D1b'
       zchar_length {} exceeds 128   r   )
ValueErrorformathashlibsha512encode	hexdigestr   r   )schar_lengthr
   hash_objecthash_hexhash_encs         r   short_str_encr   &   s|      S5<<[IIJJJ.,,K$$&&H#h++Y77HAkM""r   )r   enc_table_16enc_table_64r   r    r   r   <module>r#      sN     "Q  < "#l # # # # # #r   