-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcifrar.py
More file actions
121 lines (91 loc) · 4.41 KB
/
Copy pathcifrar.py
File metadata and controls
121 lines (91 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import tkinter as tk
from tkinter import ttk
import algoritmo
import socket
class CifrarApp:
def __init__(self, master):
self.master = master
self.master.title("Cifrar App")
self.master.geometry("820x720")
self.master.config(padx=10, pady=10)
# Apply Clam theme
style = ttk.Style()
style.theme_use('clam')
# Create the encryption object
self.encryption = algoritmo
# Create the GUI
self.create_gui()
# Set the icon of the window
self.master.iconbitmap("lock.ico")
def create_gui(self):
# Create the menu
menu_bar = tk.Menu(self.master)
self.master.config(menu=menu_bar)
# Create the File menu
file_menu = tk.Menu(menu_bar, tearoff=0)
file_menu.add_command(label="Exit", command=self.master.quit)
menu_bar.add_cascade(label="File", menu=file_menu)
# Main panel for left and right panels
self.main_panel = ttk.Frame(self.master, width=700, height=600)
self.main_panel.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
# Left panel for message input
self.left_panel = ttk.Frame(self.main_panel, width=200, height=600)
self.left_panel.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
self.left_panel.pack_propagate(0)
self.message_label = ttk.Label(self.left_panel, text="Mensaje:")
self.message_label.pack()
self.message_entry = tk.Text(self.left_panel, height=10)
self.message_entry.pack(fill=tk.BOTH, expand=True)
self.encrypt_button = ttk.Button(self.left_panel, text="Encriptar", command=self.encrypt_message)
self.encrypt_button.pack()
self.send_button = ttk.Button(self.left_panel, text="Enviar", command=self.send_message)
self.send_button.pack()
# Right panel for output
self.right_panel = ttk.Frame(self.main_panel, width=500, height=600)
self.right_panel.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
self.right_panel.pack_propagate(0)
self.encrypted_message_label = ttk.Label(self.right_panel, text="Mensaje encriptado:")
self.encrypted_message_label.pack()
self.encrypted_message_text = tk.Text(self.right_panel, height=10)
self.encrypted_message_text.pack(fill=tk.BOTH, expand=True)
self.key_label = ttk.Label(self.right_panel, text="Clave hash:")
self.key_label.pack()
self.key_text = tk.Text(self.right_panel, height=5)
self.key_text.pack(fill=tk.BOTH, expand=True)
self.steps_label = ttk.Label(self.right_panel, text="Pasos:")
self.steps_label.pack()
# Add a scrollbar to the steps_text widget
self.steps_scrollbar = ttk.Scrollbar(self.right_panel)
self.steps_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.steps_text = tk.Text(self.right_panel, height=15, yscrollcommand=self.steps_scrollbar.set)
self.steps_text.pack(fill=tk.BOTH, expand=True)
self.steps_scrollbar.config(command=self.steps_text.yview)
def encrypt_message(self):
try:
message = self.message_entry.get("1.0", tk.END).encode()
encrypted_message, key, steps = self.encryption.encrypt_message(message)
self.encrypted_message_text.delete("1.0", tk.END)
self.encrypted_message_text.insert(tk.END, encrypted_message.hex())
self.key_text.delete("1.0", tk.END)
self.key_text.insert(tk.END, key.hex())
self.steps_text.delete("1.0", tk.END)
self.steps_text.insert(tk.END, "\n".join(steps))
except Exception as e:
tk.messagebox.showerror("Error", f"An error occurred while encrypting the message: {e}")
def send_message(self):
# Get the encrypted message and key
encrypted_message = self.encrypted_message_text.get("1.0", tk.END).strip()
key = self.key_text.get("1.0", tk.END).strip()
# Combine the message and key into a single string, separated by '|'
message_and_key = f"{encrypted_message}|{key}"
# Create a socket and connect to the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("25.66.221.245", 58765))
# Send the message and key to the server
s.sendall(message_and_key.encode())
# Close the socket
s.close()
if __name__ == "__main__":
root = tk.Tk()
app = CifrarApp(root)
root.mainloop()