|
| 1 | +#A encryption decryption program using GUI by sudoshivesh |
| 2 | +import tkinter as tk |
| 3 | +import tkinter.font as tkfont |
| 4 | +from tkinter import * |
| 5 | +from tkinter.ttk import * |
| 6 | + |
| 7 | +root = tk.Tk() |
| 8 | + |
| 9 | +pic = PhotoImage(file = "C:\\Users\\admin\\Desktop\\EncDec\\image\\images.png") |
| 10 | +root.iconphoto(False,pic) |
| 11 | +root.title("Text Encryptor-Decryptor") |
| 12 | + |
| 13 | +root.geometry("400x500") |
| 14 | +root.resizable(width=FALSE, height=FALSE) |
| 15 | + |
| 16 | +canvas = tk.Canvas(root,height = 500, width=400, bg="MediumPurple1") |
| 17 | +canvas.pack() |
| 18 | + |
| 19 | +bold_font = tkfont.Font(family="Helvetica",size=12,weight="bold") |
| 20 | + |
| 21 | +label1 = tk.Label(root,text= "Enter the Text",width=20,bg="MediumPurple1") |
| 22 | +label1.config(font=bold_font) |
| 23 | +canvas.create_window(200,100,window=label1) |
| 24 | +user_text = tk.Entry(root) |
| 25 | +canvas.create_window(200,150,window=user_text) |
| 26 | + |
| 27 | +label2=tk.Label(root,text="Choose an Operation",width=25,bg="MediumPurple1") |
| 28 | +label2.config(font=bold_font) |
| 29 | +canvas.create_window(200,200,window=label2) |
| 30 | + |
| 31 | +v = tk.IntVar() |
| 32 | + |
| 33 | +def choice(): |
| 34 | + x = v.get() |
| 35 | + if(x==1): |
| 36 | + encryption() |
| 37 | + elif(x==2): |
| 38 | + decryption() |
| 39 | + |
| 40 | +label3=tk.Radiobutton(root, text="Encryption",padx = 20, variable=v, value=1,command=choice,bg="light yellow") |
| 41 | +label3.config(font=bold_font) |
| 42 | +canvas.create_window(100,250,window=label3) |
| 43 | +label4=tk.Radiobutton(root, text="Decryption",padx = 20, variable=v, value=2,command=choice,bg="light yellow") |
| 44 | +label4.config(font=bold_font) |
| 45 | +canvas.create_window(300,250,window=label4) |
| 46 | + |
| 47 | +def encryption(): |
| 48 | + plain_text = user_text.get() |
| 49 | + cipher_text = "" |
| 50 | + key = 3 |
| 51 | + for i in range(len(plain_text)): |
| 52 | + letter = plain_text[i] |
| 53 | + if(letter.isupper()): |
| 54 | + cipher_text+=chr((ord(letter)+key-65)%26+65) |
| 55 | + else: |
| 56 | + cipher_text+=chr((ord(letter)+key-97)%26+97) |
| 57 | + label5 =tk.Label(root,text=cipher_text,width=20,bg="light yellow") |
| 58 | + label5.config(font=bold_font) |
| 59 | + canvas.create_window(200,350,window=label5) |
| 60 | + |
| 61 | +def decryption(): |
| 62 | + cipher_text = user_text.get() |
| 63 | + plain_text = "" |
| 64 | + key = 3 |
| 65 | + for i in range(len(cipher_text)): |
| 66 | + letter = cipher_text[i] |
| 67 | + if(letter.isupper()): |
| 68 | + plain_text+=chr((ord(letter)-key-65)%26+65) |
| 69 | + else: |
| 70 | + plain_text+=chr((ord(letter)-key-97)%26+97) |
| 71 | + label6 =tk.Label(root,text=plain_text,width=20,bg="light yellow") |
| 72 | + label6.config(font=bold_font) |
| 73 | + canvas.create_window(200,350,window=label6) |
| 74 | + |
| 75 | +label7 =tk.Label(root,text="Converted Text ",width=20,bg="MediumPurple1") |
| 76 | +label7.config(font=bold_font) |
| 77 | +canvas.create_window(200,300,window=label7) |
| 78 | + |
| 79 | +root.mainloop() |
0 commit comments