-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.py
More file actions
38 lines (28 loc) · 1.03 KB
/
decrypt.py
File metadata and controls
38 lines (28 loc) · 1.03 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
# try block to handle the exception
try:
# take path of image as a input
path = r'https://github.com/soheilsheikh/PRODIGY_CS_02/blob/main/Data.jpg?raw=true'
# taking decryption key as input
key = int(input('Enter Key for encryption of Image : '))
# print path of image file and decryption key that we are using
print('The path of file : ', path)
print('Note : Encryption key and Decryption key must be same.')
print('Key for Decryption : ', key)
# open file for reading purpose
fin = open(path, 'rb')
# storing image data in variable "image"
image = fin.read()
fin.close()
# converting image into byte array to perform decryption easily on numeric data
image = bytearray(image)
# performing XOR operation on each value of bytearray
for index, values in enumerate(image):
image[index] = values ^ key
# opening file for writting purpose
fin = open(path, 'wb')
# writing decryption data in image
fin.write(image)
fin.close()
print('Decryption Done...')
except Exception:
print('Error caught : ', Exception.__name__)