0
votes

Okay I am working on a video processing project and this include encryption of each frame and writing it to a file (outputenc.avi). I use a key.jpg to encrypt each file using XOR operation and its going well but the problem is during decryption I am getting a noisy original image the key and the frame under process are GRAY SCALE images with dimension 384*288.

encyption

capWebcam.read(matOriginal);
if(matOriginal.empty()==true)
    return;
cv::Mat temp;
cv::resize(matOriginal,matOriginal,dsize,0,0,cv::INTER_CUBIC);
cv::cvtColor(matOriginal,matProcessed,CV_BGR2GRAY);

cv::bitwise_xor(matProcessed,key,temp);
output_enc_cap.write(temp);

decryption

capfile.read(temp);
if(temp.empty()==true)
      return;

cvtColor(temp,temp,CV_BGR2GRAY);
cv::bitwise_xor(temp,key,temp);
1
My feeling is that the problem you're unhappy about might be due to lossy compression somewhere in your processing chain. JPG is lossy. I don't know about AVI. However, a bigger problem is (assuming I'm understanding you right) that you think that XORing each frame with the same key is good encryption. It's pretty much the same as the Vigenere cipher, which was broken over 100 years ago. Look into a good implementation of AES (libgcrypt is nice) rather than trying to make your own encryption. - Neil Forrester
Sir, I just need a low profile encryption. - hunter

1 Answers

1
votes

There are more issues with your code:

First, you convert your frame to grayscale:

cv::cvtColor(matOriginal,matProcessed,CV_BGR2GRAY);

then send it to your file. From this point on, there is NO way to get your color image back.

Then, you are saving the image with a (most probably lossy) codec. A lossy codec looses some information in the process. And it only guarantees that an compressed image will look similar to the original one. No guarantee that it will be identical. And because the "encrypted" image is noise, the result will be noise. But probably a completely different noise.

Then, this line tries to do in-place an algorithm that cannot work in place. But more than that, you wrote a grayscale image in the file, then you try to convert it to grayscale as if it was color. Complete nonsense.

cvtColor(temp,temp,CV_BGR2GRAY);

Then, you try the "decription algorithm" on an image that is anything but the "encrypted" one.

Sorry, but each line in your code is nonsense.

So, my advice is to start lower: Learn about codecs, learn about encryption and security, read what others have done on this topic, and then start.

Btw, creating your own encryption algorithm is not the best idea (at least when you are not a specialist in criptography): https://security.stackexchange.com/questions/25585/is-my-developers-home-brew-password-security-right-or-wrong-and-why