Kellyss's picture
Update app.py
a586d25 verified
import gradio as gr
from substitution_cipher import encrypt, decrypt
# Funciones adaptadas para interfaz
def cifrar_texto(texto, clave):
if not texto or not clave:
return "⚠️ Ingresa texto y clave."
try:
return encrypt(texto, clave)
except Exception as e:
return f"Error al cifrar: {e}"
def descifrar_texto(texto_cifrado, clave):
if not texto_cifrado or not clave:
return "⚠️ Ingresa texto cifrado y clave."
try:
return decrypt(texto_cifrado, clave)
except Exception as e:
return f"Error al descifrar: {e}"
# Interfaz con Gradio
with gr.Blocks(theme="soft") as demo:
gr.Markdown("## 🔐 Cifrado por Sustitución (Confusión / Ofuscación)")
gr.Markdown("Inspirado en el mecanismo **SubBytes de AES** — solo sustitución, sin permutación.")
with gr.Tab("Cifrar"):
texto = gr.Textbox(label="Texto a cifrar")
clave = gr.Textbox(label="Clave", type="password")
boton_cifrar = gr.Button("🔒 Cifrar")
salida_cifrado = gr.Textbox(label="Texto cifrado (Base64)")
boton_cifrar.click(fn=cifrar_texto, inputs=[texto, clave], outputs=salida_cifrado)
with gr.Tab("Descifrar"):
texto_cifrado = gr.Textbox(label="Texto cifrado (Base64)")
clave2 = gr.Textbox(label="Clave", type="password")
boton_descifrar = gr.Button("🔓 Descifrar")
salida_descifrado = gr.Textbox(label="Texto descifrado")
boton_descifrar.click(fn=descifrar_texto, inputs=[texto_cifrado, clave2], outputs=salida_descifrado)
demo.launch()