# Cypher v1.0
# Python version 3.2
#
# Created by Will Watts
# Secret Code generator using a XOR cypher.
from tkinter import *
from itertools import zip_longest
class Application(Frame):
""" GUI application for XOR Cypher. """
def __init__(self, master):
""" Initialize Frame. """
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create widgets to get password and message and display code. """
#Instruction label
Label(self,
text = "CYPHER"
).grid(row = 0, column = 0, sticky = W)
#password label
Label(self,
text = "Password:"
).grid(row = 3, column = 0, sticky = W)
self.password_ent = Entry(self, show="*")
self.password_ent.grid(row = 3, column = 1, sticky = W)
#message box
self.message_txt = Text(self,
width = 75,
height = 10,
wrap = WORD)
self.message_txt.grid(row = 5, column = 0, columnspan = 4)
#cypher button
Button(self,
text = "Cypher",
command = self.cypher
).grid(row = 8, column = 0, sticky = W)
def cypher(self):
key = self.password_ent.get()
data = self.message_txt.get(0.0, END)
coded = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in zip_longest(data, key, fillvalue = '-'))
self.message_txt.delete(0.0, END)
self.message_txt.insert(0.0, coded)
root = Tk()
root.title("CYPHER")
app = Application(root)
root.mainloop()