title: Brute Force Caeser Cipher Python
body: <p><a href="https://en.wikipedia.org/wiki/Caesar_cipher" rel="nofollow">https://en.wikipedia.org/wiki/Caesar_cipher</a></p>
  
  <p>Hey all, I'm doing this as an assignment for Uni. I'm so close to finishing, yet I'm stuck on the last section. I'm sure it's something basic, but I've spent close to four hours trying to find my errors using print statements and all.</p>
  
  <p>Basically the idea is that it will just brute force decrypt the user's encrypted message by cycling through all -26 offsets. My problem is that I can get the code to cycle through 26 times, but it simply will not decrypt the message for each offset.. if that makes sense.</p>
  
  <p>Correct Sample Output:</p>
  
  <pre><code>Please enter string to decrypt: ykixkz&amp;yw{oxxkr
  
  Offset: -1 = Decrypted string: xjhwjy%xvznwwjq
  Offset: -2 = Decrypted string: wigvix$wuymvvip
  Offset: -3 = Decrypted string: vhfuhw#vtxluuho
  Offset: -4 = Decrypted string: ugetgv"uswkttgn
  Offset: -5 = Decrypted string: tfdsfu!trvjssfm
  Offset: -6 = Decrypted string: secret squirrel
  Offset: -7 = Decrypted string: rdbqds}rpthqqdk
  Offset: -8 = Decrypted string: qcapcr|qosgppcj
  Offset: -9 = Decrypted string: pb`obq{pnrfoobi
  Offset: -10 = Decrypted string: oa_napzomqennah
  Offset: -11 = Decrypted string: n`^m`oynlpdmm`g
  Offset: -12 = Decrypted string: m_]l_nxmkocll_f
  Offset: -13 = Decrypted string: l^\k^mwljnbkk^e
  Offset: -14 = Decrypted string: k][j]lvkimajj]d
  Offset: -15 = Decrypted string: j\Zi\kujhl`ii\c
  Offset: -16 = Decrypted string: i[Yh[jtigk_hh[b
  Offset: -17 = Decrypted string: hZXgZishfj^ggZa
  Offset: -18 = Decrypted string: gYWfYhrgei]ffY`
  Offset: -19 = Decrypted string: fXVeXgqfdh\eeX_
  Offset: -20 = Decrypted string: eWUdWfpecg[ddW^
  Offset: -21 = Decrypted string: dVTcVeodbfZccV]
  Offset: -22 = Decrypted string: cUSbUdncaeYbbU\
  Offset: -23 = Decrypted string: bTRaTcmb`dXaaT[
  Offset: -24 = Decrypted string: aSQ`Sbla_cW``SZ
  Offset: -25 = Decrypted string: `RP_Rak`^bV__RY
  Offset: -26 = Decrypted string: _QO^Q`j_]aU^^QX
  </code></pre>
  
  <p>My output:</p>
  
  <pre><code>Please enter string to decrypt: ff
  
  Offset: -1 = Decrypted string: ff
  Offset: -2 = Decrypted string: ff
  Offset: -3 = Decrypted string: ff
  Offset: -4 = Decrypted string: ff
  Offset: -5 = Decrypted string: ff
  Offset: -6 = Decrypted string: ff
  Offset: -7 = Decrypted string: ff
  Offset: -8 = Decrypted string: ff
  Offset: -9 = Decrypted string: ff
  Offset: -10 = Decrypted string: ff
  Offset: -11 = Decrypted string: ff
  Offset: -12 = Decrypted string: ff
  Offset: -13 = Decrypted string: ff
  Offset: -14 = Decrypted string: ff
  Offset: -15 = Decrypted string: ff
  Offset: -16 = Decrypted string: ff
  Offset: -17 = Decrypted string: ff
  Offset: -18 = Decrypted string: ff
  Offset: -19 = Decrypted string: ff
  Offset: -20 = Decrypted string: ff
  Offset: -21 = Decrypted string: ff
  Offset: -22 = Decrypted string: ff
  Offset: -23 = Decrypted string: ff
  Offset: -24 = Decrypted string: ff
  Offset: -25 = Decrypted string: ff
  Offset: -26 = Decrypted string: ff
  </code></pre>
  
  <p>My code (I've cut most the program out)</p>
  
  <pre><code>choice = 0
  
  print ('*** Menu ***\n')
  
  print ('1. Encrypt string')
  print ('2. Decrypt string')
  print ('3. Brute force decryption')
  print ('4. Quit\n')
  
      elif choice == 3:
          print ('In command 3 - Brute force')
          userString = input('\nPlease enter string to decrypt: ')
          userList = list(userString)
          offsetValue = 0
          decryptIndex = 0
          while offsetValue != -26 : # Once the count reaches -26 stop, hammer time
              while decryptIndex &lt; len(userList):
                  decryptChr = chr(ord(userList[decryptIndex]) + offsetValue)
                  userList[decryptIndex] = decryptChr
                  decryptIndex += 1
                  offsetValue -= 1
              userString = ''.join(userList)
              print ('Offset',offsetValue,' = Decrypted string:' ,userString)
          print ('\n*** Menu ***\n')
          print ('1. Encrypt string')
          print ('2. Decrypt string')
          print ('3. Brute force decryption')
          print ('4. Quit\n')
          choice = int(input('What would you like to do? [1,2,3,4]? '))
          while choice != 1 and choice != 2 and choice != 3 and choice != 4:
              choice = int(input('\nPlease re-enter either [1,2,3,4] '))
  
  print ('\nGoodbye.')
  </code></pre>
  
  <p>Any ideas?!</p>