title: Encrypt a Python state machine
body: <p>I would like to create a finite state machine that my users cannot see, but can import as a module; or possibly as an encrypted text file to be decrypted and eval(); or ??? I'm open to suggestion as I'm really unsure how to proceed.</p>
  
  <ul>
  <li>It must be able to handle NumPy arrays.</li>
  <li>The remainder of the script must be open source to the user.</li>
  <li>Use of the machine would eventually expire.</li>
  </ul>
  
  <p>The state machine must remain NATURAL INTELLECTUAL PROPERTY; 100% secure hidden.</p>
  
  <p>How would I go about this? Here is a sample of what I'm looking to do:</p>
  
  <pre><code>import random
  import time
  import numpy as np
  
  def state_machine(a,b,c):
      # This machine should be hidden from users
      expiration = 1500000000
      if time.time() &lt; expiration:
          state = 0
          if a[-1]&gt;b[-1]&lt;c[-1]:
              state = 1
          elif a[-1]&lt;b[-1]&lt;c[-1]:
              state = -1
          return state
      else:
          return 'subscription expired'
  
  def generate_3_random():
      # Generate some random data for testing purposes
      a = np.random.random(2)
      b = np.random.random(2)
      c = np.random.random(2)
      return a,b,c
  
  a,b,c = generate_3_random()
  print [a,b,c]
  state = state_machine(a,b,c)
  print state
  </code></pre>
  
  <p>Sample output</p>
  
  <pre><code>&gt;&gt;&gt;[array([ 0.320481  ,  0.83016095]), array([ 0.15776184,  0.35658263]), array([ 0.96922252,  0.78727468])]
  3
  </code></pre>
  
  <p>Taking a module path, the user version would then look like this:</p>
  
  <pre><code>import my_encrypted_machine
  import random
  import time
  import numpy as np
  
  def generate_3_random():
  
      # Generate some random data for testing purposes
      a = np.random.random(2)
      b = np.random.random(2)
      c = np.random.random(2)
      return a,b,c
  
  a,b,c = generate_3_random()
  
  print [a,b,c]
  
  state = my_encrypted_machine.state_machine(a,b,c)
  
  print state
  </code></pre>
  
  <p>Output would then be in the same format as the non protected version above.</p>