python - Why is encrypt() returning None? -


i know it's little gutsy ask bunch of people through several blocks of code try anyway. trying create clone of enigma (the german encryption machine used in world war two) in python tk. looking through code logically,the method encrypt() either returning string "alert", highly unlikely, or returning none. please give quick dedicated glance can fix this? thank you.

from tkinter import * string import letters import tkmessagebox  root = tk() root.title("enigmatk")  def rank(x, d = dict((letr,n%26+1) n,letr in enumerate(letters[0:52]))):     return d[x]   def shift(key, array):     counter = range(len(array))     new = counter     in counter:         new[i] = array[i-key]     return new  alph = ["a", "b", "c", "d", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "] roti = ["a", "b", "c", "d", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "] rotii = ["a", "b", "c", "d", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "] rotiii = ["a", "b", "c", "d", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "] ref = ["a", "b", "c", "d", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "e", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "]  label = label(root, text="input:") label.pack(side = left) entry = entry(root) entry.pack(side = right) input = entry.get() rotor_set = map(rank, input[:3]) message = input[3:]   def encrypt():     new_message = message     in xrange(len(message)):         e in range(rotor_set[2]):             new_message[a] = alph[roti.index(rotii[rotiii.index(ref[rotiii.index(rotii[roti.index(alph[a])])])])]             = + 1             rotiii = shift(1, rotiii)         in range(rotor_set[1]):             new_message[a] = alph[roti.index(rotii[rotiii.index(ref[rotiii.index(rotii[roti.index(alph[a])])])])]             = + 1             rotii = shift(1, rotii)         o in range(rotor_set[0]):             new_message[a] = alph[roti.index(rotii[rotiii.index(ref[rotiii.index(rotii[roti.index(alph[a])])])])]             = + 1             roti = shift(1, roti)     return new_message   def show():     tkmessagebox.showinfo( "english enigma", encrypt())   e = button(root, text = "encrypt", command = show) e.pack() root.mainloop() 

the alphabets near top same. change if problem solved. thank you.

my guess encrypt throwing exception translated alert tk. might able see exception if start program command-line.

if exception, guess trying modify new_message doing new_message[a] = .... if new_message string (or tuple), not allowed in python strings immutable. instead, use list:

new_message = list(message) 

and join message when return:

return ''.join(new_message) 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -