title: Crypto Python Encryption
body: <p>I am trying to create a program that generates a coded message that looks like gibberish to any outsiders.</p>
  
  <p>I want it to allow a message to be encrypted using any rotation amount. So, users will be able to type a message in the terminal and specify a rotation amount (13, 4, 600, etc) and the program will print the resulting encrypted message.</p>
  
  <p>The final interactive program will run like this:</p>
  
  <p>$ python caesar.py
  Type a message:
  Hello, World!
  Rotate by:
  5
  Mjqqt, Btwqi!</p>
  
  <p>I using some helper functions to help break the problem down into manageable steps.</p>
  
  <p>I have tried writing a function called alphabet_position(letter), which receives a letter ( a string with only one alphabetic character) and returns the 0-based numerical position of that letter within the alphabet, assigning the values of 0 to a and A, 1 to b and B, all the way up to 25 for z and Z.</p>
  
  <p>Then I wrote another function rotate_character(char, rot) which receives a character char ( a string of length 1), and an integer rot. The function should return a new string of length 1, the result of rotating char by rot number of places to the right. It should use the alphabet_position function above and wrap back around to the beginning of the alphabet if the rotation is greater than 25.</p>
  
  <p>Then, I wrote one more function called encrypt(text, rot) which receives an input of a string and an integer. The second argument, rot, specifies the rotation amount. The function should return the result of rotating each letter in the text by rot places to the right.</p>
  
  <p>The result in the terminal should look like this:</p>
  
  <p>$ python caesar.py
  Type a message:
  Hello, World!
  Rotate by:
  5
  Mjqqt, Btwqi!</p>
  
  <p>For the final portion of this, I want to create a Vigenere cipher.</p>
  
  <p>Vigenere uses a word as the encryption key, rather than an integer. The finished program will behave like this:</p>
  
  <p>$ python vigenere.py
  Type a message:
  The crow flies at midnight!
  Encryption key:
  boom
  Uvs osck rmwse bh auebwsih!</p>
  
  <p>If you could provide any information on what I have done incorrectly with this code, I would appreciate it.</p>
  
  <pre><code>def encrypt(text,rot):
      text_new = ""
      for pos in range(len(text)):
          text_new += rotate_character(text[pos],int(rot))
      return text_new
  
  def alphabet_position(letter):
      alphabet_pos = {'A':0, 'a':0, 'B':1, 'b':1, 'C':2, 'c':2, 
  'D':3, 'd':3, 'E':4, 'e':4, 'F':5, 'f':5, 'G':6, 'g':6, 'H':7, 
  'h':7, 'I':8, 'i':8, 'J':9, 'j':9, 'K':10, 'k':10, 'L':11, 'l':11, 
  'M':12, 'm':12, 'N':13, 'n':13, 'O':14, 'o':14, 'P':15, 'p':15, 
  'Q':16, 'q':16, 'R':17, 'r':17, 'S':18, 's':18, 'T':19, 't':19, 
  'U':20, 'u':20, 'V':21, 'v':21, 'W':22, 'w':22, 'X':23, 'x':23, 
  'Y':24, 'y':24, 'Z':25, 'z':25}
      pos = alphabet_pos[letter]
      return alphabet_position(letter)
  
  def rotate_character(char,rot):
      x = (alphabet_position(char))
      y = (x + rot)%26
      if (ord(char) &gt;= 97) and (ord(char) &lt;= 122): # lowercase
          return x.lower
      elif (ord(char) &gt;= 65) and (ord(char) &lt;=90): # uppercase
          return x.upper
      else:
          return char
  
  char = input('Enter a character:')
  rot = input('Enter a number to rotate by:')
  print(rotate_character(char,rot))
  
  
  def main():
      text = input("Type a message")
      print("text")
      rot = input("Rotate by:")
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>Instead of the expected results of encrypting the message, the terminal returned this instead: 
  line 10, in alphabet_position
      return alphabet_position(letter)
    [Previous line repeated 987 more times]
  RecursionError: maximum recursion depth exceeded</p>