
    ,h)                     n   d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
 ddlmZ 	 ddlmZ d	Z	 dd
eded   dedededededefdZdededed   dedef
dZd
eded   dedefdZd
ededededeeef   f
dZd
eded   dedededededeeef   fdZdeeef   dedefdZy# e$ r	 ddlmZ Y w xY w)z,Anything related to encryption / decryption.    N)md5)TupleUnion   )b_ord_str_)ByteStringObject)Literals    (N^NuAd NV.. h>/dSizpasswordrev)         keylenowner_entryp_entry	id1_entrymetadata_encryptreturnc                    t        t        |       t        t              z   dd       }t        |      }|j	                  |j
                         t        j                  d|      }	|j	                  |	       |j	                  |j
                         |dk\  r|s|j	                  d       |j                         }
|dk\  r,t        d      D ]  }t        |
d|       j                         }
  |
d| S )z
    Implementation of algorithm 3.2 of the PDF standard security handler.

    See section 3.5.2 of the PDF 1.6 reference.
    N    z<ir   s   2   )
r   r	   _encryption_paddingr   updateoriginal_bytesstructpackdigestrange)r   r   r   r   r   r   r   password_bytesmp_entry_bytesmd5_hash_s               R/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/PyPDF2/_security.py_alg32r'   6   s    & h$/B*CCSbIJN 	NA HH[''( KKg.MHH] HHY%%& ax(	$%xxzH axr 	7A8GV,-446H	7 GV    owner_passworduser_passwordc                     t        | ||      }t        |t        t              z   dd       }t	        ||      }|dk\  r@t        dd      D ]1  }d}|D ]  }	|t        t        |	      |z        z  } t	        ||      }3 |S )z{
    Implementation of algorithm 3.3 of the PDF standard security handler,
    section 3.5.2 of the PDF 1.6 reference.
    Nr   r   r       )_alg33_1r   r	   r   RC4_encryptr    chrr   )
r)   r*   r   r   keyuser_password_bytesvalinew_keykey_chars
             r&   _alg33r7   l   s     >3
/C md3F.GG"MN c.
/C axq" 	,AG 33tH~1223gs+C		, Jr(   c                     t        | t        t              z   dd       }t        |      }|j	                         }|dk\  r)t        d      D ]  }t        |      j	                         } |d| }|S )zSteps 1-4 of algorithm 3.3Nr   r   r   )r   r	   r   r   r   r    )r   r   r   r!   r"   r$   r%   r1   s           r&   r.   r.      sx    
 D)<$==sCDN 	NA xxzH
axr 	.A8}++-H	. 7F
CJr(   c                 R    d}d}t        | |||||      }t        |t              }||fS )
    Implementation of algorithm 3.4 of the PDF standard security handler.

    See section 3.5.2 of the PDF 1.6 reference.
    r      )r'   r/   r   )r   r   r   r   r   r   r1   Us           r&   _alg34r=      s<     CF
3Wi
HC 	C,-A c6Mr(   c           
      n   t        | |||||      }t               }|j                  t               |j                  |j                         |j                         }	t        ||	      }
t        dd      D ]:  }d}|D ]%  }|t        t        t        |      |z              z  }' t        ||
      }
< |
dz   |fS )r:   r   r,   r(   s                   )r'   r   r   r   r   r   r/   r    r   r0   r   )r   r   r   r   r   r   r   r1   r"   r$   r3   r4   r5   ks                 r&   _alg35r@      s      3Wi
HC 	AHH !
 HHY%%&xxzH c8
$C 1b\ ( 	,Ar#d1gk*++G	,'3'	( ,$$r(   r1   	plaintextc           
         t        t        d            }d}t        d      D ]9  }|||   z   t        | |t        |       z           z   dz  }||   ||   c||<   ||<   ; d\  }}g }|D ]f  }|dz   dz  }|||   z   dz  }||   ||   c||<   ||<   |||   ||   z   dz     }|j	                  t        t        t        |      |z                     h dj                  |      S )N   r   )r   r   r   r(   )listr    r   lenappendr   r0   join)r1   rA   Sjr4   retvalplaintext_charts           r&   r/   r/      s   U3ZA	A3Z  1XSSX.//36qT1Q4
!ad  DAqF# 9UcM1XqT1Q4
!adqtad{c!"bT.1A56789 88Fr(   )T)__doc__r   hashlibr   typingr   r   _utilsr   r   r	   genericr
   r   ImportErrortyping_extensionsr   strintboolbytesr'   r7   r.   r=   r@   r/    r(   r&   <module>rY      s  < 3    " " %*   "33		3 3 "	3
 3  3 3 3l(+29'2BLO
@s !1 3 5 .!   	
 5%<2/%/%		/% /% "	/%
 /%  /% /% 5%</%dU3:& 5 U K  * **s   B& &B43B4