Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,40 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from substitution_cipher import encrypt, decrypt
|
| 3 |
|
| 4 |
+
# Funciones adaptadas para interfaz
|
| 5 |
+
def cifrar_texto(texto, clave):
|
| 6 |
+
if not texto or not clave:
|
| 7 |
+
return "⚠️ Ingresa texto y clave."
|
| 8 |
+
try:
|
| 9 |
+
return encrypt(texto, clave)
|
| 10 |
+
except Exception as e:
|
| 11 |
+
return f"Error al cifrar: {e}"
|
| 12 |
+
|
| 13 |
+
def descifrar_texto(texto_cifrado, clave):
|
| 14 |
+
if not texto_cifrado or not clave:
|
| 15 |
+
return "⚠️ Ingresa texto cifrado y clave."
|
| 16 |
+
try:
|
| 17 |
+
return decrypt(texto_cifrado, clave)
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error al descifrar: {e}"
|
| 20 |
+
|
| 21 |
+
# Interfaz con Gradio
|
| 22 |
+
with gr.Blocks(theme="soft") as demo:
|
| 23 |
+
gr.Markdown("## 🔐 Cifrado por Sustitución (Confusión / Ofuscación)")
|
| 24 |
+
gr.Markdown("Inspirado en el mecanismo **SubBytes de AES** — solo sustitución, sin permutación.")
|
| 25 |
+
|
| 26 |
+
with gr.Tab("Cifrar"):
|
| 27 |
+
texto = gr.Textbox(label="Texto a cifrar")
|
| 28 |
+
clave = gr.Textbox(label="Clave", type="password")
|
| 29 |
+
boton_cifrar = gr.Button("🔒 Cifrar")
|
| 30 |
+
salida_cifrado = gr.Textbox(label="Texto cifrado (Base64)")
|
| 31 |
+
boton_cifrar.click(fn=cifrar_texto, inputs=[texto, clave], outputs=salida_cifrado)
|
| 32 |
+
|
| 33 |
+
with gr.Tab("Descifrar"):
|
| 34 |
+
texto_cifrado = gr.Textbox(label="Texto cifrado (Base64)")
|
| 35 |
+
clave2 = gr.Textbox(label="Clave", type="password")
|
| 36 |
+
boton_descifrar = gr.Button("🔓 Descifrar")
|
| 37 |
+
salida_descifrado = gr.Textbox(label="Texto descifrado")
|
| 38 |
+
boton_descifrar.click(fn=descifrar_texto, inputs=[texto_cifrado, clave2], outputs=salida_descifrado)
|
| 39 |
|
|
|
|
| 40 |
demo.launch()
|