Encryption is the process of converting information or data into a secrete code, especially to prevent unauthorized access. In these cases also we will do the same, For encryption, we will convert the image into a byte array and after converting it we will apply XOR operation on each value of the byte array and after performing XOR operation on each and every value of byte array will be changed. After performing the operation now we will write new data in Image due to which we are unable to open the Encrypted Image. Here are key will act as a password to Encrypt and Decrypt the Image. As we know that how to perform XOR operations now we will see how XOR operation will work here. Let’s consider an example of sample input and output.
Input:
int key = 8 int byte_val = 5 Operation:
// Performing XOR operation between key and byte_val key ^ byte_val
Output:
// Output of XOR operation 13
Operation:
// Performing XOR operation between output and key 13 ^ key
Output: // byte_val 5