title: Repeating a word to match the length of a string
body: <p>In school we are currently using python to create a Caeser Cipher, and a Keyword Cipher. I need help with certain parts of the Keyword cipher, mainly repeating a word to match the length of a string that has been entered, For example:</p>
  
  <p><strong>Entered String</strong>: Hello I am Jacob    <strong>Key</strong>: bye   <strong>Printed text</strong>: byebyebyebyeb</p>
  
  <p>I'm okay at Python, but this is very hard for me. Currently this is as far as I got:</p>
  
  <pre><code>def repeat_to_length(key, Input):
  return (key * ((ord(Input)/len(key))+1))[:ord(Input)]
  </code></pre>
  
  <p>Since It's a string I thought if I used ord It would turn it to a number, but I realised when using the ord command you can only have a single character, as I realised when I repeatedly got this error:</p>
  
  <pre><code>TypeError: ord() expected a character, but string of length 16 found
  </code></pre>
  
  <p>I found some code that did a keyword cipher, but I am not sure which part does the process I am trying to code:</p>
  
  <pre><code>def createVigenereSquare():
     start = ord('a')
     end = start + 26
     index = start
     sq = [''] * 256   
     for i in  range(start, end):
        row = [''] * 256
        for j in  range(start, end):
           if index &gt; (end - 1):
              index = start
           row[j] = chr(index)
           index += 1
        sq[i] = row
        index = i + 1 
     return sq
  
  def createKey(message, keyword):
     n = 0
     key = ""
     for i in range(0, len(message)):
         if n &gt;= len(keyword):
           n = 0
        key += keyword[n]
        n += 1
     return key
  
  def createCipherText(message, key):
     vsquare = createVigenereSquare()
     cipher = ""
      for i in range(0, len(key)):
        cipher += vsquare[ord(key[i])][ord(message[i])]
     return cipher
  
  message = str(input("Please input a message using lowercase letters: "))
  keyword = str(input("Please input a single word with lowercase letters: "))
  key = createKey(message, keyword)
  ciphertext = createCipherText(message, key)
  print ("Message: " + message)
  print ("Keyword: " + keyword)
  print ("Key: " + key)
  print ("Ciphertext: " + ciphertext)
  </code></pre>
  
  <p>As I've said I'm only okay at Python, so I don't really understand all the code in the above code, and I really want to be able to write most of it myself.
  This is my code so far:</p>
  
  <pre><code>def getMode():
        while True:
             print("Enter encrypt, e, decrypt or d")
             mode = input('Do you want to encrypt the message or decrypt? ')    #changes whether the code encrypts or decrypts message
             if mode in 'encrypt e decrypt d ENCRYPT E DECRYPT D'.split():      #defines the various inputs that are valid
                   return mode
             else:
                   print('Enter either "encrypt" or "e" or "decrypt" or "d".')       #restarts this string of code if the input the user enters is invalid
  
  Input = input('Enter your message: ')
  
  key = input('Enter the one word key: ')
  
  def repeat_to_length(key, Input):
     return (key * ((ord(Input)/len(key))+1))[:ord(Input)]
  
  encryptedKey = repeat_to_length(key, Input)
  
  print(encryptedKey)
  </code></pre>
  
  <p>I know I've been pretty long winded but if anyone could provide any information on this topic, like explaining the code for the keyword cipher, or just answering my question, I would appreciate it!</p>
  
  <p>AnimeDeamon</p>