Caeser Cipher Cracking Python
<p>I am running this using Python 2.7.12</p>

<pre><code>charset="ABCDEFGHIJKLMNOPQRSTUVWXYZ" # The list of characters to be    encrypted
numchars=len(charset) # number of characters that are in the list for encryption

 def caesar_crack(crackme,i,newkey):

    print '[*] CRACKING - key: %d; ciphertext: %s' % (i,crackme)
    crackme=crackme.upper()
    plaintext='' #initialise plaintext as an empty string

    while i &lt;= 26:
        for ch in crackme:   #'for' will check each character in plaintext against charset
            if ch in charset:
                pos=charset.find(ch)    #finds the position of the current character
                pos=pos-newkey
            else:
                new='' # do nothing with characters not in charet
            if pos&gt;=len(charset):   #if the pos of the character is more or equal to the charset e.g -22 it will add 26 to get the correct letter positioning/value
                pos=pos+26
            else:
                new=charset[pos]
            plaintext=plaintext+new
        print '[*] plaintext: ' + plaintext

        if i &lt;= 27:
                newkey=newkey+1
                i=i+1
        return plaintext

def main():
    # test cases
    newkey=0
    i=0
    crackme = 'PBATENGHYNGVBAFLBHUNIRPENPXRQGURPBQRNAQGURFUVSGJNFGUVEGRRA' 
    # call functions with text cases
    caesar_crack(crackme,i,newkey)

# boilerplate
if __name__ == '__main__':
    main()
</code></pre>

<p>This is what I have thus far, I am currently looking to get this to loop multiple times, prefferably 26 (1 for each number/letter of the alphabet).</p>

<p>I feel as though what I have should work just fine but I'm almost certain that what I have should work but upon running it will only run once eg <code>newkey = 0</code> and <code>i = 0</code> but will increment to the next value <code>newkey = 1</code> and <code>i = 1</code> but will not then rerun.</p>

<p>Can anyone spot the fatal flaw that I'm missing? Or any tips as to how to make it run more efficiently, all would be appreciated.</p>

<p>just move the indentation of </p>

<pre><code>return plaintext
</code></pre>

<p>one step to left</p>

<p>that will resolve the looping issue and it will go through all 26 numbers</p>

<p>didnt check the remaining of the program if it is good </p>

python python-2.7 caesar-cipher