title: "List index out of range" error in python 3 file
body: <p>I have a homemade text encryption script which outputs a "List index out of range" error when I input "Hey dude, how are you doing?" as a text to encrypt and "KFC" as an encryption key. </p>
  
  <p>I get this more precisely:</p>
  
  <p><code>Traceback (most recent call last):
    File "/Users/BCPianist/Google Drive/Project-Cryptonite/NCrypt.py", line 75, in &lt;module&gt;
      main(userIn, a)
    File "/Users/BCPianist/Google Drive/Project-Cryptonite/NCrypt.py", line 47, in main
      currentscrtrank += 1 + scrtlst[scrtrankcounter]
  IndexError: list index out of range</code></p>
  
  <p>I have two files used in this script (the main script and a function library). I just can't figure where this error is coming from...
  Here is my main script:</p>
  
  <pre><code>import random
  from cryptolib import *
  
  # !/usr/bin/env python
  # -*- coding: UTF-8 -*-
  # enable debugging
  print("Content-Type: text/plain;charset=utf-8")  # Definit le code d'ecriture
  print()  # Insere une ligne d'espacement.
  
  
  def main(userin, numberedsecretkey):  # Fonction principale (le gros de l'encryption)
      """
     This is my main.
     &gt;&gt;&gt; main("Allo", "Hey")
     10842839726
     """
      comments = True  # Definit si les commentaires lors de l'impression sont actif ou non (False les desactive)
      total = convdecimal(userin)  # Time to deal with the encryption key:
  
      scrtkeytotal = convdecimal(numberedsecretkey)
  
      # converting numbered message to list
      msglst = [int(elem) for elem in str(total)]
      if comments == True:
          printdebug("The initial numbered message is:%s " % msglst)
      # converting numbered key to list
      scrtlst = [int(thingy) for thingy in str(scrtkeytotal)]
      if not comments != True:
          printdebug("The initial  encryption key is:%s" % scrtlst)
  
      # Attempting Encryption
  
      scrtrankcounter = 0
      currentscrtrank = scrtlst[scrtrankcounter]
  
      while currentscrtrank &lt; len(msglst):
          randomgen = random.randint(0, 9)
          msglst.insert(currentscrtrank, randomgen)
          if comments:
              printdebug(str(randomgen) + " was inserted at rank: " + str(
                  scrtrankcounter) + ", therefore, at index position: " + str(currentscrtrank) + ".")
              printdebug("List now appears as: " + str(msglst))
          scrtrankcounter += 1
          if scrtrankcounter &gt; len(scrtlst):
              scrtrankcounter = 0
  
          currentscrtrank += 1 + scrtlst[scrtrankcounter]
  
      return listtoint(msglst)
  
  
  def convdecimal(userin):
      rank = len(userin)
      total = 0
      for character in userin:
          rank -= 1  # decreasing the letter rank by one
  
          letter = ord(character)
          if letter &lt; 32:
              pass
          elif letter == 27:
              pass
          else:
              rankmult = 255 ** rank  # Making a multiplier
              lettervalue = letter * rankmult  # Multiplying the letter by this multiplier
              total += lettervalue  # Adding the letter's value to the total
  
      return total
  
  
  if __name__ == "__main__":
      userIn = input("Enter the word/Sentence you want to encrypt:")
      a = input("Enter a password with which you would like to encrypt your message:")
      print(userIn)
      main(userIn, a)
  </code></pre>
  
  <p>And here is my function library file:</p>
  
  <pre><code>import os
  
  DEBUG = True
  
  
  def printdebug(log: object) -&gt; object:
      if DEBUG:
          print(log)
  
  
  def loading(sec=10):
      start = 1
      input("Press Enter to continue")
      printdebug("loading...")
      while start &lt;= sec:
          printdebug("...")
          start += 1
  
  
  def codepause():
      os.system("Pause")
      input("press enter to continue")
  
  
  def listtoint(msglst):
      # Conversion from list to int
      """
     &gt;&gt;&gt; listtoint([1,2,3,4,5,6,7,8,9,0])
     1234567890
     """
      ncryptedkey = 0
      base = 10
      for d in msglst:
          ncryptedkey = base * ncryptedkey + d
      # printDebugJob:
      printdebug("The encrypted message is:" + str(ncryptedkey))
      return ncryptedkey
  
  
  def convdecimal(userin):
      rank = len(userin)
      total = 0
      for character in userin:
          rank -= 1  # decreasing the letter rank by one
  
          letter = ord(character)
          if letter &lt; 32:
              pass
          elif letter == 27:
              pass
          else:
              rankmult = 255 ** rank  # Making a multiplier
              lettervalue = letter * rankmult  # Multiplying the letter by this multiplier
              total += lettervalue  # Adding the letter's value to the total
  
  
  def letterprint(nb):
      nb = chr(nb)
  
      print(nb, end='')
  </code></pre>
  
  <p>Thanks Already!</p>