-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalCode.py
More file actions
42 lines (32 loc) · 1.28 KB
/
FinalCode.py
File metadata and controls
42 lines (32 loc) · 1.28 KB
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
#file1
from email.mime import image
import PIL.Image
#file2
def encrypt_image(image_path, key):
with image.open(image_path, 'r') as img:
pixel_data = list(img.getdata())
encrypted_data = [value ^ key for value in pixel_data]
with image.new(img.mode, img.size) as new_img:
new_img.putdata(encrypted_data)
new_img.save('encrypted_' + image_path)
def decrypt_image(encrypted_image_path, key):
with image.open(encrypted_image_path, 'r') as img:
pixel_data = list(img.getdata())
decrypted_data = [value ^ key for value in pixel_data]
with image.new(img.mode, img.size) as new_img:
new_img.putdata(decrypted_data)
new_img.save('decrypted_' + encrypted_image_path)
#file3
if __name__ == "__main__":
image_path = input("Enter path of Image: ")
key = int(input("Enter Key for encryption of Image: "))
print("The path of file: ", image_path)
print("Key for encryption: ", key)
encrypt_image(image_path, key)
print("Encryption Done...")
key = int(input("Enter Key for decryption of Image: "))
encrypted_image_path = "encrypted_" + image_path
print("The path of file: ", encrypted_image_path)
print("Key for decryption: ", key)
decrypt_image(encrypted_image_path, key)
print("Decryption Done...")