title: Substitution Encryption (ProblemSetQuestion) in Python
body: <p>Winkleson here with another question for a <a href="http://singpath.appspot.com" rel="nofollow noreferrer">http://singpath.appspot.com</a> problemset question. I am a beginner programmer who would like some guidance whenever I can. Anyways I came up to this question here and I am not sure how to proceed without wasting time by comparing EVERY.SINGLE.LETTER. in if statements. So I would love any hints/solutions to cut down on the coding for this question. I'll post what I have so far (not much). Thanks in advance!</p>
  <p>Question:</p>
  <hr />
  <blockquote>
  <p><strong>Substitution Encryption</strong></p>
  <p>Create a program that can be used to encrypt
  and decrypt a string of letters. The function should take input of a
  string to encode and a string of letters giving the new order of the
  alphabet. The second string contains all characters of the alphabet
  but in a new order. This order tells what letters to swap. The first
  letter in the second string should replace all the a's in the first
  string. The third letter of the second string should replace all c's
  in the first string. Your solution should be in all lower case. Be
  careful of punctuation and digits (these should not change).</p>
  </blockquote>
  <p>Examples (calls):</p>
  <pre><code>&gt;&gt;&gt; encrypt('hello banana','qwertyuiopasdfghjklzxcvbnm')
  'itssg wqfqfq'
  
  &gt;&gt;&gt; encrypt('itssg wqfqfq','kxvmcnophqrszyijadlegwbuft')
  'hello banana'
  
  &gt;&gt;&gt; encrypt('gftw xohk xzaaog vk xrzxnkh','nxqlzhtdvfepmkoywrjiubscga')
  'this code cannot be cracked'
  
  &gt;&gt;&gt; encrypt('mkhzbc id hzw pwdh vtcgxtgw ube fbicg ozth kbx tew fbicg','monsrdgticyxpzwbqvjafleukh')
  'python is the best language for doing what you are doing'
  </code></pre>
  <p>My code:</p>
  <hr />
  <pre><code>def encrypt(s, realph):
      
      alph = 'abcdefghijklmnopqrstuvwxyz' #Regular Alphabet
      news = '' #The decoded string   
          
      #All comparison(s) between realph and alph    
          
      for i in range(len(realalph)):        
          
          #Comparison Statement here too.
          news = ''.join(alph) 
      
      return news
  </code></pre>
  <p>As you can see this is obviously the equivalent to failed pseudocode... As always any suggestions and/or solutions would be amazing! Thanks in advance! - Winkleson</p>