from Tkinter import *
import tkMessageBox
from string import *
from random import *
class Application(Frame):
def info(self):
tkMessageBox.showinfo("Text", "This program uses two different encryption methods to produce one encrypted text")
def helps(self):
tkMessageBox.showinfo("Text", "Enter your plain text first, Then enter your two keys and click encrypt to get your plain text encrypted")
def createWidgets(self):
#Menu Bar!
self.menubar = Menu(self)
filemenu = Menu(self.menubar, tearoff=0)
filemenu.add_command(label="Info",command = self.info)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
self.menubar.add_cascade(label="File", menu=filemenu)
helpmenu = Menu(self.menubar, tearoff=0)
helpmenu.add_command(label="Instructions", command=self.helps)
self.menubar.add_cascade(label="Help", menu=helpmenu)
root.config(menu=self.menubar)
#Text Objects
self.ptext = Text(self, width = 30, height = 10)
self.ptext.grid(row = 2, column = 3)
self.key1 = Text(self, width = 30, height = 2)
self.key1.grid(row = 4, column = 3)
self.key2 = Text(self, width = 30, height = 2)
self.key2.grid(row = 6, column = 3)
#self.encrypt(plain ,firstkey ,secondkey)
#Buttons
self.crypt = Button(self, text = "Encrypt", command = self.encrypt)
self.crypt.grid(row = 10, column = 1)
#self.encrypt()
#labels
self.lptext = Label(self, text = "Enter Plain Text Here:")
self.lptext.grid(row = 2, column = 0)
self.lkey1 = Label(self, text = "Enter First Key Here:")
self.lkey1.grid(row = 4, column = 0)
self.lkey2 = Label(self, text = "Enter Second Key Here:")
self.lkey2.grid(row = 6, column = 0)
#return plain, firstkey, secondkey
def encrypt(self):
plain = self.ptext.get(1.0,END)
firstkey = self.key1.get(1.0,END)
secondkey = self.key2.get(1.0,END)
block = []
arraychar = []
key1 = []
throwaway = []
plainarray = []
cyphertext = []
inc = 0
count = 0
place = 0
avalchars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789`-=~!@#$%^&*()_+[]<>{}|;':,/"
firstkey = firstkey.rstrip("\n")
plain = plain.rstrip("\n")
lenkey1 = len(str(firstkey))
#Switching Strings to Arrays
for ch in str(firstkey):
key1.append(ch)
for ch in str(avalchars):
throwaway.append(ch)
for ch in str(plain):
plainarray.append(ch)
#End swiching strings to arrays
#finding length
lenthrow = len(throwaway)
#Making the plain text an even number of characters by appending an additional
#character to the end
if len(plainarray)%2 != 0:
rand = randint(0,lenthrow)
findch = throwaway[rand]
plainarray.append(findch)
throwaway.remove(findch)
lenthrow = lenthrow - 1
#gets random characters if length is < 9
if lenkey1 < 9:
rang = 9 - lenkey1
for i in range(rang):
rand = randint(0,lenthrow)
findch = throwaway[rand]
key1.append(findch)
throwaway.remove(findch)
lenthrow = lenthrow - 1
#eliminates doubles from the key as doubles increased the length of avalchars past 90
#which creates more than a 9 by 10 block and eliminates some symbols
for i in range(lenkey1):
char = key1[i]
chcount = key1.count(char)
if chcount > 1:
key1.remove(char)
rand = randint(0,lenthrow)
findch = throwaway[rand]
key1.append(findch)
throwaway.remove(findch)
lenthrow = lenthrow - 1
#gets the char from key 1 and finds that character in aval chars and replaces it with a ? in aval chars
for index in range(len(key1)):
ch = key1[index]
avalchars = avalchars.replace(ch,"?")
#appends chars as the first 9 characters in array chars
for x in range(len(key1)):
ch = key1[x]
arraychar.append(ch)
#appends chars from aval chars to arraychars, if the char is ? it removes it from arraychar
#to keep the 90 characters and remove the characters that are in the first key from the block
for ch in str(avalchars):
arraychar.append(ch)
if ch == "?":
arraychar.remove("?")
#creates the block and fills it with arraychars by rows and columns
for row in range(10):
block.append([])
if row > 0:
count = row*9
for column in range(9):
inc = count + column
block[row].append(arraychar[inc])
#first step to encryting the plain text
while place < len(plainarray):
firstch = plainarray[place]
secondch = plainarray[place+1]
print block.index(plainarray[place])
print block.index(plainarray[place+1])
place = place + 2
def __init__(self,master =None):
Frame.__init__(self, master, height = 300, width= 450)
self.grid_propagate(0)
self.grid()
self.createWidgets()
#self.encrypt(x,y,z)
root = Tk()
app = Application(master = root)
app.mainloop()
so in lines 129 to 135 i create a 2d array. But in lines 140, 141 i try to find the index of a specific character in the 2d arrray and the problem that keeps occuring is that list.index(x) x doesnt exist in the array, but the problem is that it does and im worryed that it could be the fact that it is the 2d array. Any ideas on why this is occuring or how to fix it?
Thanks

New Topic/Question
Reply




MultiQuote






|