Here's my attempt at a Caesar Cipher encoder/decoder.If given a key, it will encrypt the given string.  However, if you do not specify a key, it checks each of the 26 possible keys and returns the one with the highest percentage of words that appear in this file of English words (with a couple additions including 'a' and 'I'). The program also returns the 'assurance' in its choice; for a specified key it is always 100%, for an unspecified key it is the percentage of words that are in English.How can I improve the speed of the program? I have gone through 5 versions and improved the method that I use to decrypt each time, but now I would like to improve the speed. As I am a beginner, I am not very sure on how to do this.The code is fairly readable, I think.CaesarCipher_v5.py [47 lines]# CaesarCipher_v5.py# # CSTAICH 2014from string import maketrans, ascii_uppercase, ascii_lowercaseimport refrom operator import itemgetterfrom itertools import chaininput = ''key = ''# variable input and processingwhile input == '': input = raw_input('Input ciphertext: ')if key == '': key = raw_input('Input key; leave blank for auto-detection: ')if key != '':    key = int(key)    if key >= 26: raise Exception(invalid key, must be [0-25])alphabet = list(chain(*zip(ascii_uppercase, ascii_lowercase)))english_words = re.sub(r'\r', '', open('sowpods.txt', 'r').read().lower()).split('\n')# =================================-------------------------------def key_shift(input, key): # shifts an input by a key number of characters    return input.translate(maketrans(str(alphabet), str(alphabet[key * 2:] + alphabet[:key * 2])))def english(sentence): #returns percentage of words in input that are english words    sentence = re.sub(r'[?,.!:;/]', '', sentence).split(' ') #strip punctuation and split into words    number_english_words = 0    number_words = len(sentence)    for word in sentence:        if word.lower() in english_words: number_english_words += 1    return round(number_english_words / float(number_words) * 100, 2)# begin bodyif key != '': #behavior for defined-key shift    output = key_shift(input, key)    assurance = '100%'else: #behavior for non-defined-key shift    options = [key_shift(input, s) for s in xrange(1,27)] #list of 26 options for shift    options_dict = zip(options, [english(s) for s in options]) #list of tuples: (option, percent eng)    output, assurance = max(options_dict, key=itemgetter(1))[0:2]print ' :: '.join([str(output), str(assurance) + '%'])Here are a couple interactions with the code:$ python CaesarCipher_v5.pyInput ciphertext: Here is some plain English that I would like to translate over by, let's say... 17 characters? Sound good?Input key; leave blank for auto-detection: 17Yviv zj jfdv gcrze Vexczjy kyrk Z nflcu czbv kf kirejcrkv fmvi sp, cvk'j jrp... 17 tyrirtkvij? Jfleu xffu? :: 100%%$ python CaesarCipher_v5.pyInput ciphertext: Yviv zj jfdv gcrze Vexczjy kyrk Z nflcu czbv kf kirejcrkv fmvi sp, cvk'j jrp... 17 tyrirtkvij? Jfleu xffu?Input key; leave blank for auto-detection: Here is some plain English that I would like to translate over by, let's say... 17 characters? Sound good? :: 89.47%$ python CaesarCipher_v5.pyInput ciphertext: Yberz vcfhz qbybe fvg nzrg, pbafrpgrghe nqvcvfpvat ryvg, frq qb rvhfzbq grzcbe vapvqvqhag hg ynober rg qbyber zntan nyvdhn. Hg ravz nq zvavz iravnz, dhvf abfgehq rkrepvgngvba hyynzpb ynobevf avfv hg nyvdhvc rk rn pbzzbqb pbafrdhng. Qhvf nhgr veher qbybe va erceruraqrevg va ibyhcgngr iryvg rffr pvyyhz qbyber rh shtvng ahyyn cnevnghe. Rkprcgrhe fvag bppnrpng phcvqngng aba cebvqrag, fhag va phycn dhv bssvpvn qrfrehag zbyyvg navz vq rfg ynobehzInput key; leave blank for auto-detection: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum :: 36.23%That last one was an experiment to see if it could pick out Latin. Turns out it can simply because short, two- or three-letter words are often shared between languages even if they do not have the same meaning. Even though the assurance was only 36.23%, the next best was 13.04% and many of the keys returned only one or two recognized words.
Increase the speed of this Caesar Cipher
python;performance;python 2.7;caesar cipher