ó
<­^c           @   s�   d  Z  d Z d Z y d d l m Z Wn! e k
 rI d d l m Z n Xd „  Z d „  Z d d „ Z	 e	 Z
 e d k r‹ e	 d	 d
 ƒ GHn  d S(   s9  md5crypt.py - Provides interoperable MD5-based crypt() function

SYNOPSIS

    import md5crypt.py
    cryptedpassword = md5crypt.md5crypt(password, salt);

DESCRIPTION

unix_md5_crypt() provides a crypt()-compatible interface to the
rather new MD5-based crypt() function found in modern operating systems.
It's based on the implementation found on FreeBSD 2.2.[56]-RELEASE and
contains the following license in it:

 "THE BEER-WARE LICENSE" (Revision 42):
 <phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
 can do whatever you want with this stuff. If we meet some day, and you think
 this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp

apache_md5_crypt() provides a function compatible with Apache's
.htpasswd files. This was contributed by Bryan Hart <bryan@eai.com>.

s   $1$s@   ./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyziÿÿÿÿ(   t   md5c         C   sG   d } x: | d d k rB | d } | t  |  d @} |  d ?}  q	 W| S(   Nt    i   i    i?   i   (   t   ITOA64(   t   vt   nt   ret(    (    s,   /opt/www/iredadmin/tools/../libs/md5crypt.pyt   to642   s    
c         C   s   t  |  | d ƒ S(   Ns   $apr1$(   t   unix_md5_crypt(   t   pwt   salt(    (    s,   /opt/www/iredadmin/tools/../libs/md5crypt.pyt   apache_md5_crypt;   s    c   
      C   sÂ  | d  k r t } n  | t | ƒ  | k r> | t | ƒ } n  d d  l } | j | d d ƒ d } | d  } |  | | } t |  | |  ƒ j ƒ  } xK t t |  ƒ d d ƒ D]1 } | d k rÑ | | d  } q® | | |  } q® Wt |  ƒ } x? | r0| d @r| t d ƒ } n | |  d } | d ?} qò Wt | ƒ j ƒ  } x¤ t d ƒ D]– } d	 } | d @rs| |  } n | | d  } | d
 r˜| | } n  | d r¯| |  } n  | d @rÊ| | d  } n
 | |  } t | ƒ j ƒ  } qPWd	 }	 |	 t	 t
 t | d ƒ ƒ d >t
 t | d ƒ ƒ d >Bt
 t | d ƒ ƒ Bd ƒ }	 |	 t	 t
 t | d ƒ ƒ d >t
 t | d ƒ ƒ d >Bt
 t | d ƒ ƒ Bd ƒ }	 |	 t	 t
 t | d ƒ ƒ d >t
 t | d ƒ ƒ d >Bt
 t | d ƒ ƒ Bd ƒ }	 |	 t	 t
 t | d
 ƒ ƒ d >t
 t | d ƒ ƒ d >Bt
 t | d ƒ ƒ Bd ƒ }	 |	 t	 t
 t | d ƒ ƒ d >t
 t | d ƒ ƒ d >Bt
 t | d ƒ ƒ Bd ƒ }	 |	 t	 t
 t | d ƒ ƒ d ƒ }	 | | d |	 S(   Niÿÿÿÿt   $i   i    i   iðÿÿÿi   iè  R   i   i   i   i   i   i   i   i   i	   i   i
   i   i   (   t   Nonet   MAGICt   lent   stringt   splitR    t   digestt   ranget   chrR   t   intt   ord(
   R   R	   t   magicR   t   ctxt   finalt   plt   it   ctx1t   passwd(    (    s,   /opt/www/iredadmin/tools/../libs/md5crypt.pyR   @   sf    	
	





/////#t   __main__t   catt   hatN(   t   __doc__R   R   t   hashlibR    t   ImportErrorR   R
   R   R   t   md5cryptt   __name__(    (    (    s,   /opt/www/iredadmin/tools/../libs/md5crypt.pyt   <module>(   s   			V