def computeUserPass(userPassString, dictO, fileID, pElement, keyLength=128, revision=3, encryptMetadata=False):
 userPass = ''
 dictU = ''
 dictOE = ''
 dictUE = ''
 ret = computeEncryptionKey(userPassString, dictO, dictU, dictOE, dictUE, fileID, pElement, keyLength, revision, encryptMetadata)
 if (ret[0] != (-1)):
  rc4Key = ret[1]
 else:
  return ret
 if (revision == 2):
  userPass = RC4(paddingString, rc4Key)
 elif (revision > 2):
  counter = 1
  md5Input = (paddingString + fileID)
  hashResult = hashlib.md5(md5Input).digest()
  userPass = RC4(hashResult, rc4Key)
  while (counter <= 19):
   newKey = ''
   for i in range(len(rc4Key)):
    newKey += chr((ord(rc4Key[i]) ^ counter))
   userPass = RC4(userPass, newKey)
   counter += 1
  counter = 0
  while (counter < 16):
   userPass += chr(random.randint(32, 255))
   counter += 1
 return (0, userPass)

def computeUserPass ( userPassString , dictO , fileID , pElement , keyLength = 128 , revision = 3 , encryptMetadata = False ) : userPass = '' dictU = '' dictOE = '' dictUE = '' ret = computeEncryptionKey ( userPassString , dictO , dictU , dictOE , dictUE , fileID , pElement , keyLength , revision , encryptMetadata ) if ( ret [ 0 ] != ( - 1 ) ) : rc4Key = ret [ 1 ] else : return ret if ( revision == 2 ) : userPass = RC4 ( paddingString , rc4Key ) elif ( revision > 2 ) : counter = 1 md5Input = ( paddingString + fileID ) hashResult = hashlib . md5 ( md5Input ) . digest ( ) userPass = RC4 ( hashResult , rc4Key ) while ( counter <= 19 ) : newKey = '' for i in range ( len ( rc4Key ) ) : newKey += chr ( ( ord ( rc4Key [ i ] ) ^ counter ) ) userPass = RC4 ( userPass , newKey ) counter += 1 counter = 0 while ( counter < 16 ) : userPass += chr ( random . randint ( 32 , 255 ) ) counter += 1 return ( 0 , userPass )
compute the user password of the pdf file .