Simple Crypto Script

Questions about programming languages and debugging
Post Reply
User avatar
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00

Simple Crypto Script

Post by maboroshi »

Figured I would post this code I wrote a while ago just a simple message encoder decoder using Vernam Crypto Algorithm

I would say its flawless but something puzzles me about it Vernam Crypto requires a truly random series of characters to encrypt the message but Im using the python module random.sample Im sure it would be hard to decrypt but none the less I debate how random the random module is in Python or any computer application/language maybe I will start another post discussing that

Anyway here is the code :)

Cheers Maboroshi

Code: Select all

from pycipher import *
from Tkinter import *
import random

def getMessage():
    global message
    message = message_entry.get()    
    textbox.insert(END, message + "\n\n")

def createKey():
    key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrsrstuvwxyz0123456789"
    global thegenkey
    thegenkey = ''.join(random.sample(str(key), len(message)))
    textbox.insert(END, "The Generated Vernam Key\n\n")
    global ciphertext
    ciphertext = Vernam(message).encipher(thegenkey)
    textbox.insert(END, ciphertext)

def decipherit():
    deciphertext = Vernam(ciphertext).decipher(thegenkey)
    textbox.insert(END, "\n\nThe Decrypted Vernam Message\n\n")
    textbox.insert(END, deciphertext)

root = Tk()
root.title("Vernam Crypto Script")
frame = Frame(root)
message_entry = Entry(frame)
button = Button(frame, text="Get Message", command=getMessage)
button2 = Button(frame, text="Encrypt", command=createKey)
button3 = Button(frame, text="Decrypt", command=decipherit)


frame2 = Frame(root)
textbox = Text(frame2)
textbox.pack(fill=BOTH, expand=TRUE)
frame2.pack(fill=BOTH, expand=TRUE)


Post Reply