File size: 1,581 Bytes
5fe1495
a586d25
5fe1495
a586d25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fe1495
 
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
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()