Skip to content

Commit

Permalink
Merge pull request #9 from Madff386/v2.1.0-alpha
Browse files Browse the repository at this point in the history
PKE-v2.1.0
  • Loading branch information
Madff386 committed Nov 2, 2020
2 parents 9765e22 + d94f32a commit 72156ca
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 84 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog:

### v2.1.0
Added scrollbar to output
Combined input to single window
Changed output to pop up dialog box
Added custom encryption keys

### v2.0.0
Enhanced encryption
Added documentaion
Expand Down
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ the public key encryption protocol.
It is *only* compatible with the
latest Windows operating system or any operating system with python 3.7.

### Release notes of PKE-v2.0.0: <a name="release_notes"></a>
- Enhanced encryption
- Added documentaion
- Added support for special characters
- Added support for capital letter
- Changed prompts
### Release notes of PKE-v2.1.0: <a name="release_notes"></a>
- Added scrollbar to output
- Combined input to single window
- Changed output to pop up dialog box
- Added custom encryption keys

## Installation: <a name="installation"></a>
### Built version <a name="built_version"></a>
Expand All @@ -49,20 +48,27 @@ into a directory that is easily accessible.
## Usage: <a name="usage"></a>
### Built version <a name="built"></a>
To run the built version of the PKE program, after you have downloaded it double click the
file named PKE.exe.
file named PKE-vX.X.X.exe.

### Python version <a name="python"></a>
To run the source code or the python version, right click the file called PKE.py and select
open with. Then from the menu select python 3.

### Encrypting <a name="encrypting"></a>
After you run the program you will be prompted with a blank text box. To encrypt a message follow these 2 steps.
1.Type the word, encrypt, in the blank text box and click OK.
2.Type the message you wish to encrypt any character apart from [] and ~ and click OK.
The encrypted version of the text you entered will be displayed in a new window. To go back to the Welcome screen, click OK. To exit the program click Exit.
When you run the program you will be prompted with a window with a few configuration options follow these 4 steps to encrypt a message:
1. At the top select the encrypt radiobutton
2. Then if you want to encrypt your message with a custom encryption key, type the public key into the first box and the main key into the second,
if you just want to use the default encryption key leave them blank
3. Next type your message to encrypt in the big text box and press 'run',
your encrypted text will show up in a pop up dialog box for you to copy paste out of
4. To close the dialog box press 'ok' and it will diapear then you can encrypt, decrypt or close the program, to close the program press 'cancel'

### Decrypting <a name="decrypting"></a>
After you run the program you will be prompted with a blank text box. To decrypt a message follow these 2 steps.
1. Type the word, decrypt, in the blank text box and click OK
2. Copy and Paste the sequencee you want to decrypt and press OK.
The decrypted message will be displayed in a new window. To go back to the Welcome screen, press OK, to exit the program press cancel.

### Decrypting <a name="decrypting"></a>
When you run the program you will be prompted with a window with a few configuration options follow these 4 steps to decrypt a message:
1. At the top select the decrypt radiobutton
2. Ignore the two small text boxes they are for encrypting
3. Next type the message you want to decrypt in the big text box and press 'run',
your decrypted text will show up in a pop up dialog box for you to read
4. To close the dialog box press 'ok' and it will diapear then you can encrypt, decrypt or close the program, to close the program press 'cancel'
The decrypted message will be displayed in a new window. To go back to the Welcome screen, press OK, to exit the prog
184 changes: 116 additions & 68 deletions Source/PKE.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,20 @@ def encrypt(message): # encrypt function



for thing in emessage:
for thing in emessage:
if e_key_input.get() != '' and pq_key_input.get != '':
encyption_key = int(e_key_input.get())
main_key = int(pq_key_input.get())
else:
encyption_key = e
main_key = p*q
sep = '.'
quotent = (thing**e)/(p*q) # compute quotent
quotent = (thing**encyption_key)/(main_key) # compute quotent
rquotent = str(quotent)
r = rquotent.split(sep, 1)[1] #[
r = ("0." + r)
r = mpf(r)
t = float(r)*(p*q)
t = float(r)*(main_key)
t = t*100000
t = str(t)
t = t.split(sep, 1)[0]
Expand All @@ -224,7 +230,7 @@ def decrypt(message): # decrypt function
decrypted = []
data = message.split()
for temp in data:
temp = int(temp) # splits message into listw
temp = int(temp) # splits message into list
demessage.append(temp)
for thing in demessage:
sep = '.'
Expand Down Expand Up @@ -427,83 +433,125 @@ def decrypt(message): # decrypt function

plaintext = ''.join(decrypted) # returns decrypted message as string
return plaintext




def get_task():
task = simpledialog.askstring('Task', 'Type encrypt, decrypt or exit') # creates dialog box
return task

def get_messag():
messag = simpledialog.askstring('Encrypt', 'Enter what you want to encrypt: ') # creates dialog box
return messag

def get_message():
message = simpledialog.askstring('Decrypt', 'Enter what you want to decrypt: ') # creates dialog box
return message

def oken():
outen.destroy() # destroys widow when button is press while encrypting
loop()


def okde():
outde.destroy() # destroys widow when button is press while decrypting
loop()
def output_encrypted(encrypted):
global encrypted_output_window
encrypted_output_window = Toplevel(root) # create window
encrypted_output_window.title('Encrypted')
encrypted_output_window.geometry('-520+120')
encrypted_text = StringVar()
encrypted_output = Text(encrypted_output_window, width=20, height=8)
encrypted_output.grid(column=0, row=0, sticky=(W, E), padx=10, pady=10, columnspan=2) # create lable
encrypted = str(encrypted)
encrypted = encrypted.replace(',', '')
encrypted = encrypted.replace(']', '') # make readable
encrypted = encrypted.replace('[', '')
encrypted_output.insert(END, '%s' % encrypted)
encrypted_output.configure(state="disabled")
encrypted_output.configure(wrap="word")
encrypted_scrollbar = ttk.Scrollbar(encrypted_output_window, orient=VERTICAL, command=encrypted_output.yview)
encrypted_scrollbar.grid(column=2, row=0, sticky=(N, S, W)) # create scrollbar
encrypted_output.configure(yscrollcommand=encrypted_scrollbar.set)
ok = ttk.Button(encrypted_output_window, text='Ok', command=encrypted_output_window.destroy)
ok.grid(column=1, row=2, sticky=(E), columnspan=2)
ok.focus()
ok.bind('<Return>', kill_encrypting)

def output_decrypted(decrypted):
global decrypted_output_window
decrypted_output_window = Toplevel(root) # create window
decrypted_output_window.title('Decrypted')
decrypted_output_window.geometry('-520+120')
decrypted_text = StringVar()
decrypted_output = Text(decrypted_output_window, width=20, height=8)
decrypted_output.grid(column=0, row=0, sticky=(W, E), padx=10, pady=10, columnspan=2) # create text box
decrypted = str(decrypted)
decrypted = decrypted.replace(',', '')
decrypted = decrypted.replace('~', ',')
decrypted = decrypted.replace(']', '') # remove list characters
decrypted = decrypted.replace('[', '')
decrypted_output.insert(END, '%s' % decrypted)
decrypted_output.configure(state="disabled") # display ouptut
decrypted_output.configure(wrap="word")
decrypted_scrollbar = ttk.Scrollbar(decrypted_output_window, orient=VERTICAL, command=decrypted_output.yview)
decrypted_scrollbar.grid(column=2, row=0, sticky=(N, S, W)) # create scrollbar
decrypted_output.configure(yscrollcommand=decrypted_scrollbar.set)
ok = ttk.Button(decrypted_output_window, text='Ok', command=decrypted_output_window.destroy)
ok.grid(column=1, row=2, sticky=(E), columnspan=2)
ok.focus()
ok.bind('<Return>', kill_decrypting)


def kill_encrypting(event):
encrypted_output_window.destroy()

def kill_decrypting(event):
decrypted_output_window.destroy()


def loop(): # main loop
task = get_task()
if task == 'encrypt': # when encrypting
messag = get_messag()
encrypted = encrypt(messag) # get message
global outen
outen = Toplevel(root) # create window
outen.title('Encrypted')
enout = StringVar()
labelen = Text(outen, width=20, height=8)
labelen.grid(column=0, row=0, sticky=(W, E), padx=10, pady=10, columnspan=2) # create lable
encrypted = str(encrypted)
encrypted = encrypted.replace(',', '')
encrypted = encrypted.replace(']', '') # make readable
encrypted = encrypted.replace('[', '')
labelen.insert(END, '%s' % encrypted)
labelen.configure(state="disabled")
labelen.configure(wrap="word")
ok = ttk.Button(outen, text='Ok', command=oken).grid(column=1, row=2, sticky=(E))
exit = ttk.Button(outen, text='Exit', command=root.destroy).grid(column=2, row=2, sticky=(E)) # create buttons

elif task == 'decrypt': # when decrypting
message = get_message()
decrypted = decrypt(message) # get message
global outde
outde = Toplevel(root) # create window
outde.title('Decrypted')
deout = StringVar()
labelde = Text(outde, width=20, height=8)
labelde.grid(column=0, row=0, sticky=(W, E), padx=10, pady=10) # create text box
decrypted = str(decrypted)
decrypted = decrypted.replace(',', '')
decrypted = decrypted.replace('~', ',')
decrypted = decrypted.replace(']', '') # remove list characters
decrypted = decrypted.replace('[', '')
labelde.insert(END, '%s' % decrypted)
labelde.configure(state="disabled") # display ouptut
labelde.configure(wrap="word")
ok = ttk.Button(outde, text='Ok', command=okde).grid(column=1, row=2, sticky=(E))
exit = ttk.Button(outde, text='Exit', command=root.destroy).grid(column=2, row=2, sticky=(E)) #c create buttons
else:
root.destroy() # terminate program
def run():
error_message.set('')
if "~" in message_input.get('1.0', 'end') or "[" in message_input.get('1.0', 'end') or "]" in message_input.get('1.0', 'end'):
error_message.set('Can\'t encrypt ~ [ or ]')
return

if en_or_de.get() == 'encrypt':
encrypted = encrypt(message_input.get('1.0', 'end'))
output_encrypted(encrypted)
elif en_or_de.get() == 'decrypt':
message = message_input.get('1.0', 'end')
data = message.split()
for temp in data:
try:
temp = int(temp)
except:
error_message.set('Can only decrypt numbers')
return
decrypted = decrypt(message_input.get('1.0', 'end'))
output_decrypted(decrypted)
elif en_or_de.get() == 'else':
error_message.set('Select encrypt or decrypt')
return


root = Tk()
root.withdraw()


d = mpf(851)
e = mpf(11) # set keys for encryption and decryption
p = mpf(53)
q = mpf(61)
loop()

root.mainloop()
error_message = StringVar()
en_or_de = StringVar()
en_or_de.set('else')
e_key = StringVar()
pq_key = StringVar()
root.title('Input')
root.geometry('-500+100')
frame = ttk.Frame(root)
frame['padding'] = (20, 5, 20, 5)
frame.grid(column=0, row=0, sticky=(N, E, S, W))
encrypt_or_decrypt = ttk.Label(frame, text='Do you want to encrypt or decrypt?').grid(column=3, row=1, sticky=(N, S), pady=5, padx=5, columnspan=3)
encrypt_radiobutton = ttk.Radiobutton(frame, text='Encrypt', variable=en_or_de, value='encrypt').grid(column=3, row=2, sticky=(W))
decrypt_radiobutton = ttk.Radiobutton(frame, text='Decrypt', variable=en_or_de, value='decrypt').grid(column=5, row=2, sticky=(N), columnspan=2)
ask_message = ttk.Label(frame, text='Enter the message:').grid(column=3, row=4, pady=10, columnspan=3, sticky=(N, S))
e_key_input = ttk.Entry(frame, textvariable='e_key', width=5)
e_key_input.grid(column=3, row=3, padx=10, pady=5, sticky=(E, W))
pq_key_input = ttk.Entry(frame, textvariable='pq_key', width=5)
pq_key_input.grid(column=5, row=3, padx=10, pady=5, sticky=(E, W))
message_input = Text(frame, width=20, height=5)
message_input.grid(column=3, row=5, sticky=(N), padx=10, pady=10, columnspan=3)
error = ttk.Label(frame, text='', foreground='red', textvariable=error_message)
error.grid(column=3, row=6, columnspan=3, sticky=(N), pady=5)
run_button = ttk.Button(frame, text='Run', command=run).grid(column=3, row=7, sticky=(E, W))
cancel_button = ttk.Button(frame, text='Cancel', command=root.destroy).grid(column=5, row=7, sticky=(E, W))
message_input.focus()



root.mainloop()

0 comments on commit 72156ca

Please sign in to comment.