-
Notifications
You must be signed in to change notification settings - Fork 0
/
task2.py
49 lines (33 loc) · 1.27 KB
/
task2.py
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
43
44
45
46
47
48
49
from PIL import Image
def encrypt_image(input_path, output_path, key):
img = Image.open(input_path)
pixels = img.load()
width, height = img.size
for i in range(width):
for j in range(height):
r, g, b = pixels[i, j]
# swapping red and blue channels
encrypted_pixel = (b, g, r)
pixels[i, j] = encrypted_pixel
img.save(output_path)
print("Image encrypted successfully!")
def decrypt_image(input_path, output_path, key):
img = Image.open(input_path)
pixels = img.load()
width, height = img.size
for i in range(width):
for j in range(height):
r, g, b = pixels[i, j]
# swapping red and blue channels back
decrypted_pixel = (b, g, r)
pixels[i, j] = decrypted_pixel
img.save(output_path)
print("Image decrypted successfully!")
# image path
input_image = r"C:\Users\abu76\Desktop\Internship-01\Task-02\input.jpg"
encrypted_image = r"C:\Users\abu76\Desktop\Internship-01\Task-02\decrypted_image.jpg"
decrypted_image = r"C:\Users\abu76\Desktop\Internship-01\Task-02\encrypted_image.jpg"
# Encrypt the image
encrypt_image(input_image, encrypted_image, key=None)
# Decrypt the image
decrypt_image(encrypted_image, decrypted_image, key=None)