łň
ó=ŁCc        
   @   s!  d  d k  l  Z  d  d k l Z y d  d k l Z Wn e j
 o d   Z n Xd   Z d   Z d   Z d   Z d	   Z	 d
   Z
 d   Z d  d k Z d e i f d     YZ d e i f d     YZ d e i f d     YZ d e i f d     YZ e d j o e i   n d S(   i˙˙˙˙(   t   sha(   t   randint(   t   entropyc         C   s:   d } x- t  |   D] } | t t d d   7} q W| S(   Nt    i    i˙   (   t   ranget   chrR   (   t   nt   st   i(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR      s
     c         C   s0   t  |   d j p t  t |  i d  d  S(   s.   20 bit hash, big-endian -> long python integeri   t   hexi   (   t   lent   AssertionErrort   longt   encode(   t   hstr(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   intify   s    c         C   sy   t  |   d } | d d j o | d  } n t |  d d j o d | } n | i d  } d t |  d | S(	   s   long int -> 20-character stringi   i˙˙˙˙t   Li    t   0R	   i   t    (   R	   R
   t   decode(   t   numt   str(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt	   stringify   s    c         C   s   t  |   t  |  AS(   sE   distance between two 160-bit hashes expressed as 20-character strings(   R   (   t   at   b(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   distance'   s    c          C   s&   t    }  |  i t d   |  i   S(   s4   returns a new pseudorandom globally unique ID stringi   (   R    t   updateR   t   digest(   t   h(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   newID,   s    	c         C   s   t  t |  |   S(   N(   R   t	   randRange(   t   mint   max(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   newIDInRange2   s    c         C   s   |  t  t    | |  S(   N(   R   R   (   R   R    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR   5   s    c           C   s   t  d d  S(   Ni   i   i   @i   Ŕi   @(   R   (    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   newTID8   s    Nt   NewIDc           B   s   e  Z d    Z d   Z RS(   c         C   s   |  i  t t    d  d  S(   Ni   (   t   assertEqualR
   R   (   t   self(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt
   testLength?   s    c         C   s"   x t  d  D] } |  i q Wd  S(   Nid   (   t   xrangeR&   (   R%   t   x(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   testHundredsA   s     (   t   __name__t
   __module__R&   R)   (    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR#   >   s   	t   Intifyc           B   s5   e  Z d d d f g Z d   Z d   Z d	   Z RS(   R   i   i    s   ˙l    i    i   c         C   s4   x- |  i  D]" \ } } |  i t |  |  q
 Wd  S(   N(   t   knownR$   R   (   R%   R   t   value(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt	   testKnownI   s    
 c         C   sq   t    } x | d d j o t    } q W| d  t t | d  d  } |  i t |  t |  d  d  S(   Ni˙˙˙˙s   ˙i   (   R   R   t   ordR$   R   (   R%   R   t   k(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   testEndianessOnceL   s    	 "c         C   s%   x t  d  D] } |  i   q Wd  S(   Nid   (   R'   R2   (   R%   R(   (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   testEndianessLotsR   s     t                       (   R4   i    s   ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙l                        l   ˙˙˙˙˙˙˙˙˙˙˙(   R*   R+   R-   R/   R2   R3   (    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR,   E   s
   		t
   Disantancec           B   s}   e  Z d d f d f e d  i   e d  i   f d f e d  i   e d  i   f d f g Z d	   Z d
   Z RS(   R   i   s   ˙i   l     i   t   fooi    t   barc         C   s?   x8 |  i  D]- \ } } |  i t | d | d  |  q
 Wd  S(   Ni    i   (   R-   R$   R   (   R%   t   pairt   dist(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR/   \   s    
 c         C   sg   x` t  d  D]R } t   t   t   } } } |  i t | |  t | |  At | |   q Wd  S(   Nid   (   R'   R   R$   R   (   R%   R   R(   t   yt   z(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   testCommutitive_   s     R4   s   ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙l                        l   ˙˙˙˙˙˙˙˙˙˙˙(   R*   R+   R    R   R-   R/   R<   (    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR5   V   s
   '-	t	   RandRangec           B   s   e  Z d    Z d   Z RS(   c         C   s˝   t  t    } t  t    } | | j  oJ t | |  } |  i | | j o
 | j  n d d | | | f  nE t | |  } | | j o
 | j  n p t d | | | f  d  S(   Ni   s   output out of range %d  %d  %d(   R   R   R   R$   R   (   R%   R   R   t   c(    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   testOncee   s    ;c         C   s%   x t  d  D] } |  i   q Wd  S(   Nid   (   R'   R?   (   R%   R   (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyt   testOneHundredTimeso   s     (   R*   R+   R?   R@   (    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pyR=   d   s   	
t   __main__(   R    t   randomR   R   t   ImportErrorR   R   R   R   R!   R   R"   t   unittestt   TestCaseR#   R,   R5   R=   R*   t   main(    (    (    sS   /afs/sipb.mit.edu/project/outland/src/BitTorrent/BitTorrent-4.2.2/khashmir/khash.pys   <module>   s&   		
					