+
    i                         R t ^ RIt^ RIHt ^ RIHtHtHtHtHt RR.t	Rt
RtRtR	tR
tRtR;s;s;ssR tR t]P,                  ! R4      tR tR tR tR t]! ^1RR4      tR tR tRR ltRR lt R# )a  passlib.crypto.des -- DES block encryption routines

History
=======
These routines (which have since been drastically modified for python)
are based on a Java implementation of the des-crypt algorithm,
found at `<http://www.dynamic.net.au/christos/crypt/UnixCrypt2.txt>`_.

The copyright & license for that source is as follows::

    UnixCrypt.java 0.9 96/11/25
    Copyright (c) 1996 Aki Yoshida. All rights reserved.
    Permission to use, copy, modify and distribute this software
    for non-commercial or commercial purposes and without fee is
    hereby granted provided that this copyright notice appears in
    all copies.

    ---

    Unix crypt(3C) utility
    @version 0.9, 11/25/96
    @author  Aki Yoshida

    ---

    modified April 2001
    by Iris Van den Broeke, Daniel Deville

    ---
    Unix Crypt.
    Implements the one way cryptography used by Unix systems for
    simple password protection.
    @version $Id: UnixCrypt2.txt,v 1.1.1.1 2005/09/13 22:20:13 christos Exp $
    @author Greg Wilkins (gregw)

The netbsd des-crypt implementation has some nice notes on how this all works -
    http://fxr.googlebit.com/source/lib/libcrypt/crypt.c?v=NETBSD-CURRENT
N)exc)join_byte_valuesbyte_elem_valueiranger   	int_typesexpand_des_keydes_encrypt_blocki l   l    l   ~}{w l   l   sg c            	     B    Rp RpRpW3W"3W"3W"3W3W"3W"3W!33s RsRsRsR# )z3delay loading tables until they are actually neededN))    r
       r       r       r      r    $  r      r    $  r   )r
                       l                     l                    l                   @ l         @  l        @ l        @  l         D l         D  l        D l        D  )r
   r
   @   r       r   @   r       r   @   r       r   @   r   )r
                       @l         @          l         l          Hl         H            l           l          @ l         @ l           l          l          H l         H )r
   r
      r"           r#          r$      r%     r&          r'         r(   )r
                       l                   l         l          l                 l         l         l                 l        l         l        )r
   r
      r.      r/     r0      @r1      Pr2     @r3     Pr4   )r
          @          l       @                    @    l            l       @                      @   l           l       @               l       @    l            l       @    )r
   r
      r<      r=     r>      r?     r@      rA     rB   )r
              l               @l       @l       @l      @          l                  l        l        @ l       @ l       @ l      @ )r
   r
     @ rH      rI     @rJ      rK    @ rL     rM    @rN   )r
                l                 l                l                    l           l           l          l           l          l          l         )r
   r
    @  rT      rU   @  rV      rW   @  rX      rY   @  rZ   )r
                     l                    l          l          l                   l         l         l        l          !l         !l         !l        !)r
   r
           r_           r`          ra      rb           rc           rd          re   )r
                   l                 l         l         l                 l       " l        l       "          l       "  l         l       " ))r
   r
   r
   r
   r   r   r   r   rI   rI   rI   rI      rk   rk   rk   )r
   rK   r_   l       r   i (  l        l    (   r.     l        l       i   i ( l        l    (   )r
   r
   r
   r
   r`   r`   r`   r`   r?   r?   r?   r?          rm   rm   rm   )r
   r#   rf   l       rH   l       l       l      rC   l       l       l      i  @l      l      l     )r
   r
   r
   r
   r   r   r   r   r/   r/   r/   r/   @  rn   rn   rn   )r
   rW   r   i  r<      i  i  r1   i  @i  @i @i  @i  @i @i @)r
   r
   r
   r
   r=   r=   r=   r=   rb   rb   rb   rb      rp   rp   rp   )r
   r"   r   i   r%   r&   $   i$  r[   l       l        l       l       l      l   $    l   $   )r
   rU   rO     rh   l         l         l        r^   l         l         l        l         l        l        l       )r
   r)   r6   l          rE   l        @ l        `l        ` r!              l            l           l        @   l        @  l        `   l        `  )r
   rT   r   i @  r\   l    @     l      @   l    @ @   r*   l    @     l      @   l    @ @   l         l    @    l      @  l    @ @  )r
   r7   r9   r;   r              l         0 l         0  ri   l            l           l            l          l           l         0 l         0  )r
   rP   r   l           r,   l                    l          r5   l       @         @    l       @   l       @l       @ l       @   l       @  )r
   r]   rS               rD   l          l           l           r    l          (l           l          ( l         l         (l          l         ( )r
   r   r   l         @rQ            l         @l        @r   r   l         @l        @l       l        l        @l       @)r
   r+   rg   l         r   l         @l        @ l        @rF   l         l         l        l         A l         Al        A l        A))r
   r
   r
   r
   r   r   r   r   r=   r=   r=   r=     ry   ry   ry   )r
   r?   rT   i @ rf          l    @   l    @  r"   i   i @ i @ l       l      l    @  l    @ )r
   r
   r
   r
   rU   rU   rU   rU   r1   r1   r1   r1     @r{   r{   r{   )r
   r   r[   l      @ r<   i   l       l     @ rb   i   l        l      @ i  i  l       l     @ )r
   r
   r
   r
   r   r   r   r   r#   r#   r#   r#           r|   r|   r|   )r
   rK   r`   l       r.   rl   l        l       r%   i  l       l      i  i l       l      )r
   r
   r
   r
   r/   r/   r/   r/   rW   rW   rW   rW     r}   r}   r}   )r
   r   r_   l   @    r   r   l     @  l   @ @  rO   i@  l       l   @   i   i@  l     A  l   @ A  )r
   rI   rC   i   r]   l          l          l          rS   l           l           l           rw   l           l           l           )r
   r   r*            r7   rt   l           l          r   l         P l         @l         Pl         @  l         P  l         @ l         P )r
   rH   r   i  @ rP   l         l          l         r   l         @l          @l         @l          Bl         Bl          Bl         B)r
   r+   r,   r-   r   l           ru   l          r^   l          l         l                    l           l          l          )r
   rD   rg   l       r!   l           l           l          r)   l         l         l        rs   l          l          l         )r
   rQ   rF   l         r6   l        !l          l        ! r   rx   l          l         l          l        ! l          l        ! )r
   ri   r   l       0 rE   l        @l       @l       0@rh   rj   l         l       0          @ l        @ l       @ l       0@ )r
   r    r\            r5   l       @  l       @  l       @ r9   l          l         ( l         (r:   l       @  l       @ ( l       @ ())r
     rr   i        l      l     l           l     l      l    l     l    l    l   )r
                       l                  @l         Dl        @l        D         @  l         @ l         D  l         D l        @@ l        @D l        D@ l        DD )r
   r/   rW   r}   r.   r0      rb            )r
   rE   r5          @@r7           @   r8          @@   rh   r          @         @@                    @         @          @@  )r
   r   r   r   r               r               r               )r
   rF   rD   rG   r                                   r^                             r                                )r
   @     @       l   D@        @i@@l   @     l   D@     @ iD@ l   @     l   DD     i D@iDD@l   @    l   DD    )r
                   l                   l        "  l          l      "           l       l        l      l          l       " l         l      " ))@     @ " r   r        @ " r          "        r   r   r        @                @    r   r
   r   r   r        @           " r   r   r   r   r   r   r        @ r   r   r   r
   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   )@   @      r
             @    @                     @     r   r      @       r7   r                  @     r   r7   r.      @      r   r              r   r
   r   r   r   r   r   r   r.   r   r   r   r   r   r   r   r   r   r
   r   r   r.   r   r   r   r   r   r   r   r
   r   r7   r   r   r   r   r.   r   r   r   r7   r   r   )@@       rh                r   r                   r        rW                 rW       r
   r   r   rh   r   r   r   r   r   r          r   r   r
   r   r   r   rh   rW   r   r   r   r   r   r
   r   r   r   r   r   r   rW   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   rh   r   )@     @ @       @r       @ @r
    @      @ @       @     @        @r/          @ @r   r   r   r/         @      @rE   r   r   r   r   rE   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   rE   r   r
   r   r   rE   r/   r   r   r   r   r   r   r   r   r   r   r   r   r/   r   r   )@r   r5   r        @       @                  @       @ r5   r                    @         r        @ r
   r   r   rv             r   r   r
   r   r   r   r   rv   r   r   r   r   r   r   rv   r   r5   r   r   r   r   r   r   r
   r   r   r   rv   r   r   r
   r   r   r   r   r5   r   r   r   r   r   r   r   r   )@                @     r
       @   r   rF          !  r            !      @  !        @   rr           r           @  !  r   r       @     r
   rF   r   r   r   r   r   rr   r   r   r   r   r   r   rr   r   r   r   r   r
   r   rr   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   rF   r   r   r   r   r   r   r   )@r   r^                @          @    !   @             r
   rb      @      !   @      !         r           r   r   r   r   r   r   r
   r   r   r      @        @    !r   r   r   r   r^   rb   r   r   r   r   r   r^   rb   r   r   r   r   r
   r^   r   r   r   r
   r   r   r   r   r   r   rb   r   r   r   r   r   r   r   r   )@       @                 @  r
                  @                @  r   r          r         @          @           @  r  rD   r  r  r  r  r
  r
   r  r   r   r	  r   r   rD   r  r   r   rD   r
  r  r  r   r
   r  r   r	  r  r  r  r   r  r  r  r   r  r
  r  r  r	  r  r   r  r  r
   r   r   rD   r  ))r
   rD   rF   rG   r^   r   r   r   r   r   r   r   r   r   r   r   )r
   r[   r#   l       r   l         l         l        r*   l         l         l        r~   l        l        l       )r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r
      i   i  i   i  i  i i   i  i  i i  i i i)r
   r,   r   l         r+   r-   l         l        rS   l           l           l          l           l          l          l         )r
   ri   r6   l         r   l         @ l         @ l         @ r   l          @l          @l          @l         @@l         @@l         @@l         @@)r
   r<   rO   i  r?   r@   i  i rf   l       l       l      rz   l      l      l     )r
   rU   rK   i  r=   i  i  i rC   i  i  i i  i i i)r
   r5   rE   r   rh   r   r   r   r7   r8   r   r   r   r   r   r   )r
   r`   r_   ra   r\   l         l         l        r    l         l         l        r   l        l        l       )r
   rW   r/   r}   rb   r   r   r   r.   r   r0   r   r   r   r   r   )r
         i  i   i  i  i i   i  i  i i  i i i)r
   rQ   r)   l         rP   rR   l         l        r!   l           rs   l          l           l          l          l         )r
   r   rg   l       r9   l          l          l         r]   l          l          l         l           l          l          l         )r
   r   rT   i@@  rH   i@ @ i @@ i@@@ r1   i@  @i @ @i@@ @i  @@i@ @@i @@@i@@@@)r
   r%   r   i  r"   r&   i  i rI   i  i  i i  i i i)PCXROTIE3264SPECF6464)PC1ROTPC2ROTAPC2ROTBs      P/var/www/html/photoedit/myenv/lib/python3.14/site-packages/passlib/crypto/des.py_load_tablesr  Q   sk    A
FNA
GHA
Gb  2 2 2 2	F!
FLA	
CPAF    c                Z    ^ pV F"  pW#V ^,          ,          ,          pV ^,          p K$  	  V# )z`Returns the permutation of the given 32-bit or 64-bit code with
the specified permutation table. )cpoutrs   &&  r  _permuter  9  s2    
 C3x	a  Jr  z>Qc                 ,    \         P                  V 4      # )N_uint64_structpackvalues   &r  _pack64r%  J  s    u%%r  c                 :    \         P                  V 4      ^ ,          # )r
   r!  unpackr#  s   &r  	_unpack64r)  M  s      '**r  c                 :    \         P                  V 4      R ,          # ):r  NNr   r#  s   &r  _pack56r+  P  s    u%b))r  c                 H    \         P                  R V ,           4      ^ ,          # )    r'  r#  s   &r  	_unpack56r.  S  s      51!44r  c                  a  \        S \        4      '       d   \        S 4      ^8w  d   \        R4      hMh\        S \        4      '       d;   S ^ 8  g   S \
        8  d   \        R4      h\        \        \        S 4      4      4      # \        P                  ! S RR4      h\        S 4      o \        V 3R l\         4       4      # )zDconvert DES from 7 bytes to 8 bytes (by inserting empty parity bits)zkey must be 7 bytes in sizez'key must be 56-bit non-negative integerbytes or intkeyc              3   R   <"   T F  pSV,	          ^,          ^,          x  K  	  R# 5i)   Nr  ).0shiftr1  s   & r  	<genexpr>!expand_des_key.<locals>.<genexpr>u  s"     O,c5jD0144,s   $')
isinstancebyteslen
ValueErrorr   INT_56_MASKr)  r   r+  r   ExpectedTypeErrorr.  r   _EXPAND_ITER)r1  s   fr  r   r   c  s    #us8q=:;; 	C	#	#7cK'FGG566##C??
C.C O,OOOr  c                   \        V \        4      '       d9   \        V 4      ^8w  d   \        R4      h\	        \        \        V 4      4      4      # \        V \        4      '       d   V ^ 8  g   V \        8  d   \        R4      hM\        P                  ! V RR4      hV ^,          p ^ p^ pV^88  d+   W^,          V,          ,          pV ^,          p V^,          pK1  V\        ( ,          '       d   Q hV# )zGconvert DES key from 8 bytes to 7 bytes (by discarding the parity bits)zkey must be 8 bytes in size'key must be 64-bit non-negative integerr0  r1  )r8  r9  r:  r;  r+  shrink_des_keyr)  r   INT_64_MASKr   r=  )r1  resultoffsets   &  r  rA  rA  w  s    #us8q=:;;~in566	C	#	#7cK'FGG ( ##C??AICFF
2+:&&	!+%%&&Mr  c                   \        V \        4      '       dD   \        V 4      ^8X  d   \        V 4      p M\        V 4      ^8w  d   \	        R4      h\        V 4      p M\        P                  ! V RR4      h\        V\        4      '       d(   \        V4      ^8w  d   \	        R4      h\        V4      pM\        P                  ! VRR4      h\        WW#4      p\        V4      # )aC  encrypt single block of data using DES, operates on 8-byte strings.

:arg key:
    DES key as 7 byte string, or 8 byte string with parity bits
    (parity bit values are ignored).

:arg input:
    plaintext block to encrypt, as 8 byte string.

:arg salt:
    Optional 24-bit integer used to mutate the base DES algorithm in a
    manner specific to :class:`~passlib.hash.des_crypt` and its variants.
    The default value ``0`` provides the normal (unsalted) DES behavior.
    The salt functions as follows:
    if the ``i``'th bit of ``salt`` is set,
    bits ``i`` and ``i+24`` are swapped in the DES E-box output.

:arg rounds:
    Optional number of rounds of to apply the DES key schedule.
    the default (``rounds=1``) provides the normal DES behavior,
    but :class:`~passlib.hash.des_crypt` and its variants use
    alternate rounds values.

:raises TypeError: if any of the provided args are of the wrong type.
:raises ValueError:
    if any of the input blocks are the wrong size,
    or the salt/rounds values are out of range.

:returns:
    resulting 8-byte ciphertext block.
zkey must be 7 or 8 bytesr9  r1  zinput block must be 8 bytesinput)
r8  r9  r:  r   r;  r)  r   r=  des_encrypt_int_blockr%  )r1  rF  saltroundsrC  s   &&&& r  r   r     s    B #us8q= %CX]788n##C%88 %u:?:;;% ##E7G<< #3t<F 6?r  c                   V^8  d   \        R4      hV^ 8  g   V\        8  d   \        R4      h\        V \        4      '       g   \        P
                  ! V RR4      hV ^ 8  g   V \        8  d   \        R4      h\        V\        4      '       g   \        P
                  ! VRR4      hV^ 8  g   V\        8  d   \        R4      h\        f   \        4        \        w  rErgrrR p\        V! V 4      4      pV^?,          ^,          VR	,          ^,          ,          VR
,          ^,	          ,          VR,          ^,	          ,          pV^ 8X  d   ^ ;rMcV^,	          R,          VR,          ,          p\        V\        4      pV^ ,	          R,          V^,	          R,          ,          p\        V\        4      pV'       EdI   V^,          pV EF3  w  ppV^ ,	          V,          V,          pV^ ,          V,          V,          V,          pWV^:,	          ^?,          ,          VV^2,	          ^?,          ,          ,          VV^*,	          ^?,          ,          ,          VV^",	          ^?,          ,          ,          VV^,	          ^?,          ,          ,          V	V^,	          ^?,          ,          ,          V
V^
,	          ^?,          ,          ,          VV^,	          ^?,          ,          ,          ,          pV^ ,	          V,          V,          pV^ ,          V,          V,          V,          pWV^:,	          ^?,          ,          VV^2,	          ^?,          ,          ,          VV^*,	          ^?,          ,          ,          VV^",	          ^?,          ,          ,          VV^,	          ^?,          ,          ,          V	V^,	          ^?,          ,          ,          V
V^
,	          ^?,          ,          ,          VV^,	          ^?,          ,          ,          ,          pEK6  	  YrEKQ  V^,	          R,          V^!,          R,          ,          V^#,	          R,          ,          V^,          R,          ,          p\        V\        4      # )a]  encrypt single block of data using DES, operates on 64-bit integers.

this function is essentially the same as :func:`des_encrypt_block`,
except that it operates on integers, and will NOT automatically
expand 56-bit keys if provided (since there's no way to detect them).

:arg key:
    DES key as 64-bit integer (the parity bits are ignored).

:arg input:
    input block as 64-bit integer

:arg salt:
    optional 24-bit integer used to mutate the base DES algorithm.
    defaults to ``0`` (no mutation applied).

:arg rounds:
    optional number of rounds of to apply the DES key schedule.
    defaults to ``1``.

:raises TypeError: if any of the provided args are of the wrong type.
:raises ValueError:
    if any of the input blocks are the wrong size,
    or the salt/rounds values are out of range.

:returns:
    resulting ciphertext as 64-bit integer.
zrounds must be positive integerz(salt must be 24-bit non-negative integerintr1  r@  rF  z)input must be 64-bit non-negative integerc              3     "   \          F7  w  r\        W4      p\        W24      p V\        ,          V \        ,          3x  K9  	  R# 5i)zCgiven 64-bit key, iterates over the 8 (even,odd) key schedule pairsN)r  r  _KS_MASK)ks_oddp_evenp_oddks_evens   &   r  _iter_key_schedule1des_encrypt_int_block.<locals>._iter_key_schedule  s:     #MFv.Gg-FH$fx&777 $s   AAi  i  i   l   *UU iUUUUl       <<xxl       C il   pa )r;  INT_24_MASKr8  r   r   r=  rB  r  r  r  listr  r  r  )r1  rF  rH  rI  SPE0SPE1SPE2SPE3SPE4SPE5SPE6SPE7rR  ks_listLRrQ  rN  kBCs   &&&&                 r  rG  rG    s   D z:;;ax4+%CDD c9%%##C66	qC+%BCC eY''##E5'::	ek)DEE ~ 692DD8 %c*+G /b	 
/b	 	"
/a		! /b	 	" 	 z	ArkZ'EJ,>?QrkZ'UaZ:,EFQ
 &!  'OGVR%1$AB!a')A2t|$tQUDL'992t|$%'+QUDL'9:2t|$%'+QUDL'9: 2t|$% (,QT4K'89 :A
 R%1$AB!a&(A2t|$tQUDL'992t|$%'+QUDL'9:2t|$%'+QUDL'9: 2t|$% (,QT4K'89 :A  '$ 1 d))e))+ e))	+ d))+  Avr  i)r
   r  )!__doc__structpasslibr   passlib.utils.compatr   r   r   r   __all__rT  r<  rB  _KDATA_MASK_KPARITY_MASKrM  r  r  r  r  r  r  Structr!  r%  r)  r+  r.  r>  r   rA  r   rG  r  r  r  <module>rl     s   %\  ; ;    !"  "& % % %#_P	 t$&+*5 bBP(06pEr  