text: from os import urandom
  from hashlib import md5
  
  from Crypto.Cipher import AES
  
  def derive_key_and_iv(password, salt, key_length, iv_length):
      d = d_i = b''  # changed '' to b''
      while len(d) < key_length + iv_length:
          # changed password to str.encode(password)
          d_i = md5(d_i + str.encode(password) + salt).digest()
          d += d_i
      return d[:key_length], d[key_length:key_length+iv_length]
  
  def encrypt(in_file, out_file, password, salt_header='', key_length=32):
      # added salt_header=''
      bs = AES.block_size
      # replaced Crypt.Random with os.urandom
      salt = urandom(bs - len(salt_header))
      key, iv = derive_key_and_iv(password, salt, key_length, bs)
      cipher = AES.new(key, AES.MODE_CBC, iv)
      # changed 'Salted__' to str.encode(salt_header)
      out_file.write(str.encode(salt_header) + salt)
      finished = False
      while not finished:
          chunk = in_file.read(1024 * bs)
          if len(chunk) == 0 or len(chunk) % bs != 0:
              padding_length = (bs - len(chunk) % bs) or bs
              # changed right side to str.encode(...)
              chunk += str.encode(
                  padding_length * chr(padding_length))
              finished = True
          out_file.write(cipher.encrypt(chunk))
  
  def decrypt(in_file, out_file, password, salt_header='', key_length=32):
      # added salt_header=''
      bs = AES.block_size
      # changed 'Salted__' to salt_header
      salt = in_file.read(bs)[len(salt_header):]
      key, iv = derive_key_and_iv(password, salt, key_length, bs)
      cipher = AES.new(key, AES.MODE_CBC, iv)
      next_chunk = ''
      finished = False
      while not finished:
          chunk, next_chunk = next_chunk, cipher.decrypt(
              in_file.read(1024 * bs))
          if len(next_chunk) == 0:
              padding_length = chunk[-1]  # removed ord(...) as unnecessary
              chunk = chunk[:-padding_length]
              finished = True
              out_file.write(
                  bytes(x for x in chunk))  # cha