title: How to fix 'str' object has no attribute 'encrypt'?
body: <p>I'm trying to to encrypt a message using a given public key <code>pubkey</code> that i read off a file. When I try to run my program I get an error message stating that  </p>
  
  <blockquote>
    <p>'str' object has no attribute 'encrypt'. </p>
  </blockquote>
  
  <p>I have already tried encoding the public key, but I am still getting the same error. Since I need to use these specific public key I cannot generate another random public key.<br>
  Following is my code:  </p>
  
  <pre><code>from Crypto.PublicKey import RSA
  import math
  
  def text_to_int(text):
      """
      Converts text into an integer for use in encryption.
      input: text - a plaintext message
      output: integer - an integer encoding text
      """
      integer = 0
      for char in text:
           if integer &gt; 0:
              integer = integer*256
      integer = integer + ord(char)
  return integer
  
  #Read public key
  with open('C:\\Users\\alan9\\Downloads\\Assignement2\\Supporting_Files\\HLand_Key.pub', 'rb') as f:
      read_key = f.read()
  
  
  # use the PUBLIC KEY to encrypt a message:
  message = "attack early next week"
  message_int = text_to_int(message)
  ciphertext = read_key.encrypt(message_int, None)
  
  #Write ciphertext to file 
  with open('C:\\Users\\alan9\\Downloads\\Assignement2\\Supporting_Files\\cipher.txt', 'w') as f_write:
      f_write.write(ciphertext) 
  </code></pre>
  
  <p>I expect the output to return the encrypted message in a text file named cipher using the specified public key.<br>
  Any help will be appreciated!!!</p>