
    Md                     &    d dl Z dZdZd ZdefdZy)    N0123456789abcdefz@0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_c                 |    | dk(  r|d   S t        |      }d}| r||t        | |z           z  }| |z  } | r|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      s[    & 	Av|y>DF
)CDM**	d
  $B$<       c                     |dkD  rt        dj                  |            t        j                  | j	                               }|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   &   se      S5<<[IJJ..,K$$&H#h+Y7HAk""r   )r   enc_table_16enc_table_64r   r    r   r   <module>r#      s%     "Q< "#l #r   