Advertisement
Najeebsk

IMAGE-ENCRYPT-DECRYPT.py

Feb 20th, 2024
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import filedialog
  3.  
  4. root = Tk()
  5. root.config(bg='black')
  6. root.title('Najeeb Secret Image')
  7. root.geometry("320x100")
  8.  
  9. def encrypt_image():
  10.     file1 = filedialog.askopenfile(mode='rb', filetype=[('Image Files', '*.jpg;*.png;*.jpeg;*.bmp;*.gif')])
  11.     if file1 is not None:
  12.         file_name = file1.name
  13.         key = entry1.get(1.0, END).strip()
  14.         fi = open(file_name, 'rb')
  15.         image = bytearray(fi.read())
  16.         fi.close()
  17.         for index, value in enumerate(image):
  18.             image[index] = value ^ int(key)
  19.         fil = open(file_name, 'wb')
  20.         fil.write(image)
  21.         fil.close()
  22. Label(root.master, text='Enter Secret Key :', font='10', bg='black', fg='yellow').place(x=10, y=10)        
  23. entry1 = Text(root, height=1, width=16)
  24. entry1.place(x=150, y=10)
  25.  
  26. b1 = Button(root, text="IMAGE ENCRYPT", command=encrypt_image)
  27. b1.place(x=15, y=50)
  28. b1 = Button(root, text="IMAGE DECRYPT", command=encrypt_image)
  29. b1.place(x=180, y=50)
  30.  
  31. root.mainloop()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement