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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # -*- coding: utf-8 -*- from Tkinter import * # Jesus Eduardo Martinez Hinojosa # Ventana ventana = Tk() ventana.geometry("300x300+350+80") ventana.title("Encriptador") ventana.resizable(width=False, height=False) try: ventana.iconbitmap("icono.ico") except: print("no hay icono disponible") # Clave numclave = 1 # Funciones. def boton1(): # Cifrado Cesar TAM_MAX_CLAVE = 26 def obtenerModo(): modo = "e" return modo def obtenerMensaje(): mensaje = text.get("0.0", END) return mensaje def obtenerClave(): global numclave clave = numclave return clave def obtenerMensajeTraducido(modo, mensaje, clave): if modo[0] == 'd': clave = -clave traduccion = '' for simbolo in mensaje: if simbolo.isalpha(): num = ord(simbolo) num += clave if simbolo.isupper(): if num > ord('Z'): num -= 26 elif num < ord('A'): num += 26 elif simbolo.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 traduccion += chr(num) else: traduccion += simbolo return traduccion modo = obtenerModo() mensaje = obtenerMensaje() if modo[0] != 'b': clave = obtenerClave() if modo[0] != 'b': texto = (obtenerMensajeTraducido(modo, mensaje, clave)) text.delete("0.0", END) text.insert("0.0", texto) informe1.config(text="Texto Encriptado") else: for clave in range(1, TAM_MAX_CLAVE + 1): print(clave, obtenerMensajeTraducido('desencriptar', mensaje, clave)) def boton2(): # Cifrado Cesar TAM_MAX_CLAVE = 26 def obtenerModo(): modo = "d" return modo def obtenerMensaje(): mensaje = text.get("0.0", END) return mensaje def obtenerClave(): global numclave clave = numclave return clave def obtenerMensajeTraducido(modo, mensaje, clave): if modo[0] == 'd': clave = -clave traduccion = '' for simbolo in mensaje: if simbolo.isalpha(): num = ord(simbolo) num += clave if simbolo.isupper(): if num > ord('Z'): num -= 26 elif num < ord('A'): num += 26 elif simbolo.islower(): if num > ord('z'): num -= 26 elif num < ord('a'): num += 26 traduccion += chr(num) else: traduccion += simbolo return traduccion modo = obtenerModo() mensaje = obtenerMensaje() if modo[0] != 'b': clave = obtenerClave() if modo[0] != 'b': texto = (obtenerMensajeTraducido(modo, mensaje, clave)) text.delete("0.0", END) text.insert("0.0", texto) informe1.config(text="Texto Desencriptado") else: for clave in range(1, TAM_MAX_CLAVE + 1): print(clave, obtenerMensajeTraducido('desencriptar', mensaje, clave)) def salir(): ventana.destroy() def menu_activacion(event): menu_despegable.post(event.x_root, event.y_root) def cortar(): text.clipboard_clear() text.clipboard_append(text.selection_get()) sel = text.get(SEL_FIRST, SEL_LAST) text.delete(SEL_FIRST, SEL_LAST) def copiar(): text.clipboard_clear() text.clipboard_append(text.selection_get()) def pegar(): tem = text.selection_get(selection="CLIPBOARD") text.insert(INSERT, tem) # Widget b1 = Button(ventana, text="Encriptar", bg='black', fg='white', activebackground='cyan', activeforeground='dark slate gray', command=boton1, font=("Courier New", 9)) b2 = Button(ventana, text="Desencriptar", bg='black', fg='white', activebackground='cyan', activeforeground='dark slate gray', command=boton2, font=("Courier New", 9)) text = Text(ventana, fg='lavender', bg='dark slate gray', font=("Courier New", 10)) informe1 = Label(ventana, text="Ingrese un texto", bg="turquoise", font=("Courier New", 10)) b1.place(x=10, y=260, width=120, height=30) b2.place(x=167, y=260, width=120, height=30) informe1.place(x=0, y=0, width=300, height=30) text.place(x=0, y=30, height=218, width=300) menu_despegable = Menu(ventana, tearoff=0) menu_despegable.add_command(label="Cortar", command=cortar, font=("Courier New", 9)) menu_despegable.add_command(label="Copiar", command=copiar, font=("Courier New", 9)) menu_despegable.add_command(label="Pegar", command=pegar, font=("Courier New", 9)) menu_despegable.add_separator() menu_despegable.add_command(label="Salir", command=salir, font=("Courier New", 9)) text.bind(".", menu_activacion) ventana.mainloop() |
domingo, 25 de noviembre de 2018
Encriptador P8
Suscribirse a:
Comentarios de la entrada (Atom)
No hay comentarios.:
Publicar un comentario