Situatie
Encryption
It is nothing but a simple process in which we convert our data or information into secret code to prevent it from unauthorized access and keep it private and secure.
First, we will select an image, and then we will convert that image into a byte array due to which the image data will be totally converted into numeric form, and then we can easily apply the XOR operation to it. Now, whenever we will apply the XOR function on each value of the byte array then the data will be changed due to which we will be unable to access it. But we should remember one thing here our encryption key plays a very important role without that key we can not decrypt our image. It acts as a password to decrypt it.
Solutie
Pasi de urmat
# Assign values
data = 1281
key = 27
# Display values
print(‘Original Data:’, data)
print(‘Key:’, key)
# Encryption
data = data ^ key
print(‘After Encryption:’, data)
# Decryption
data = data ^ key
print(‘After Decryption:’, data)
Output:
Original Data: 1281 Key: 27 After Encryption: 1306 After Decryption: 1281
Here in the above program, as we can see how XOR operation works, it takes two variables data and a key, whenever we perform XOR operation on them for the first time we get encrypted data. Then when we perform the XOR operation between our data and key again, we get the same value as our input variable data (decrypted data). The same logic will be applicable to a byte array of Images during encryption and decryption.
Output:
Enter path of Image : C:\Users\lenovo\Pictures\Instagram\enc.png Enter Key for encryption of Image : 22 The path of file : C:\Users\lenovo\Pictures\Instagram\enc.png Key for encryption : 22 Encryption done...
Leave A Comment?