Unidad No.4: Practica #8: Encriptacion de texto

#Aqui insertamos el codigo
# -*- 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))
 
# Empaquetado de los widget
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 popup(menu despegable)
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))
 
# Evento del menu despegable
text.bind("", menu_activacion)
 
# donde mantener el enfoque.
ventana.mainloop()

No hay comentarios:

Publicar un comentario

Unidad No.4 Triangulo en 3D

import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * verticies = (     (1, -1, -1),     (1, 1,...