|
| 1 | +from tkinter import * |
| 2 | +from tkinter import filedialog,messagebox |
| 3 | +from PIL import Image,ImageTk |
| 4 | +import os |
| 5 | +from stegano import lsb |
| 6 | + |
| 7 | +win = Tk() |
| 8 | +win.geometry('700x480') |
| 9 | +win.config(bg='black') |
| 10 | +win.title("Message Hiding in Image") |
| 11 | +#Button Function |
| 12 | +def open_img(): |
| 13 | + global open_file |
| 14 | + open_file = filedialog.askopenfilename(initialdir=os.getcwd(), |
| 15 | + title='Select File Type', |
| 16 | + filetypes=(('PNG file','*.png'),('JPG file','*.jpg'), |
| 17 | + ('All file','*.txt'))) |
| 18 | + img = Image.open(open_file) |
| 19 | + img = ImageTk.PhotoImage(img) |
| 20 | + lf1.configure(image=img) |
| 21 | + lf1.image=img |
| 22 | +def hide(): |
| 23 | + global hide_msg |
| 24 | + password = code.get() |
| 25 | + if password == '1234': |
| 26 | + |
| 27 | + msg = text1.get(1.0,END) |
| 28 | + hide_msg = lsb.hide(str(open_file),msg) |
| 29 | + messagebox.showinfo('Success','Your message is sucessfully hideen in a image,please save your image') |
| 30 | + elif password == '': |
| 31 | + messagebox.showerror('Error','Please enter Secret key') |
| 32 | + else: |
| 33 | + messagebox.showerror('Error','Wrong Sectret Key') |
| 34 | + code.set('') |
| 35 | + |
| 36 | +def save_img(): |
| 37 | + hide_msg.save('Secret file.png') |
| 38 | + messagebox.showinfo('Saved','Image has been successfully saved') |
| 39 | +def show(): |
| 40 | + password = code.get() |
| 41 | + if password == '1234': |
| 42 | + show_msg = lsb.reveal(open_file) |
| 43 | + text1.delete(1.0,END) |
| 44 | + text1.insert(END,show_msg) |
| 45 | + elif password == '': |
| 46 | + messagebox.showerror('Error', 'Please enter Secret key') |
| 47 | + else: |
| 48 | + messagebox.showerror('Error', 'Wrong Sectret Key') |
| 49 | + code.set('') |
| 50 | + |
| 51 | +#Heading |
| 52 | +Label(win,text='Message Hiding in Image',font='impack 30 bold',bg='black',fg='red').place(x=260,y=12) |
| 53 | +#Frame 1 |
| 54 | +f1 = Frame(win,width=250,height=220,bd=5,bg='purple') |
| 55 | +f1.place(x=50,y=100) |
| 56 | +lf1 = Label(f1,bg='purple') |
| 57 | +lf1.place(x=0,y=0) |
| 58 | + |
| 59 | +#Frame 2 |
| 60 | +f2 = Frame(win,width=320,height=220,bd=5,bg='white') |
| 61 | +f2.place(x=330,y=100) |
| 62 | +text1 = Text(f2,font='ariel 15 bold',wrap=WORD) |
| 63 | +text1.place(x=0,y=0,width=310,height=210) |
| 64 | + |
| 65 | +# Label for Secret Key |
| 66 | +Label(win,text='Enter Secret Key',font='10',bg='black',fg='yellow').place(x=250,y=330) |
| 67 | + |
| 68 | +#Entry Widget for secret key |
| 69 | +code=StringVar() |
| 70 | +e = Entry(win,textvariable=code,bd=2,font='impact 10 bold ',show='*') |
| 71 | +e.place(x=245,y=360) |
| 72 | + |
| 73 | +#Buttons |
| 74 | +open_button = Button(win,text='Open Image',bg='blue',fg='white',font='ariel 12 bold ',cursor='hand2',command=open_img) |
| 75 | +open_button.place(x=60,y=417) |
| 76 | + |
| 77 | +save_button = Button(win,text='Save Image',bg='green',fg='white',font='ariel 12 bold ',cursor='hand2',command=save_img) |
| 78 | +save_button.place(x=190,y=417) |
| 79 | + |
| 80 | +hide_button = Button(win,text='Hide Data',bg='red',fg='white',font='ariel 12 bold ',cursor='hand2',command=hide) |
| 81 | +hide_button.place(x=380,y=417) |
| 82 | + |
| 83 | +show_button = Button(win,text='Show Data',bg='orange',fg='white',font='ariel 12 bold ',cursor='hand2',command=show) |
| 84 | +show_button.place(x=510,y=417) |
| 85 | + |
| 86 | + |
| 87 | +mainloop() |
0 commit comments