title: How to optimize Python simple encryption?
body: <p>So I am doing a simple cipher in <strong>Python</strong> and now trying to figure out how to optimize it.</p>
  <p>I have a words <code>library = ['ab, 'ba', 'ac' ... ]</code> (library.length = 127) and each character of the input string I encode with the word from the library, so for example</p>
  <pre><code>a becomes ab, b becomes ba, etc
  </code></pre>
  <p>My goal is to iterate the encoding which would be something like:</p>
  <pre><code>[iterations = 3] ab -&gt; abba -&gt; abbabaab -&gt; abbaabbaababba
  </code></pre>
  <p>Now I'm just trying to optmise it and was wondering what would be the best way?</p>
  <p>*lock can be passed for example [31, 51, 41], where the number represents the shifting of the library to encode.</p>
  <pre><code>library = ['ab', 'ba', 'bc' ...]
  
  def encode(message, locks=[0]):
      for key in locks:
          encrypted = ''
          for char in message:
              encrypted += library[(ord(char) + key) % 128] + &quot; &quot;
          message = encrypted
      return encrypted
  </code></pre>