code: def decrypt_PBEWithSHAAndTwofishCBC(encrypted_data, password, salt, iteration_count):
      
      iv  = derive_key(hashlib.sha1, PURPOSE_IV_MATERIAL,  password, salt, iteration_count, 16)
      key = derive_key(hashlib.sha1, PURPOSE_KEY_MATERIAL, password, salt, iteration_count, 256//8)
  
      encrypted_data = bytearray(encrypted_data)
      encrypted_data_len = len(encrypted_data)
      if encrypted_data_len % 16 != 0:
          raise BadDataLengthException("encrypted data length is not a multiple of 16 bytes")
  
      plaintext = bytearray()
  
      # slow and dirty CBC decrypt
      from twofish import Twofish
      cipher = Twofish(key)
  
      last_cipher_block = bytearray(iv)
      for block_offset in range(0, encrypted_data_len, 16):
          cipher_block = encrypted_data[block_offset:block_offset+16]
          plaintext_block = xor_bytearrays(bytearray(cipher.decrypt(bytes(cipher_block))), last_cipher_block)
          plaintext.extend(plaintext_block)
          last_cipher_block = cipher_block
  
      plaintext = strip_pkcs7_padding(plaintext, 16)
      return bytes(plaintext)
docs: Decrypts PBEWithSHAAndTwofishCBC, assuming PKCS#12-generated PBE parameters.
      (Not explicitly defined as an algorithm in RFC 7292, but defined here nevertheless because of the assumption of PKCS#12 parameters).