Projects Inventory

Video Encryption/Decryption Gaming Project in C++

Explanation

  1. Include Libraries:
    • #include <opencv2/opencv.hpp>: Includes OpenCV for video processing.
    • #include <iostream>: Used for input and output operations.
    • Advertisement
  2. XOR Cipher Function (xorCipher):
    • void xorCipher(Mat& frame, char key): Function that applies XOR encryption/decryption to the video frame.
    • frame.forEach<uchar>([&key](uchar& pixel, const int* position): Iterates through each pixel in the frame and XORs it with the given key.
    • Advertisement
  3. Open Video File:
    • VideoCapture cap("path/to/your/video.mp4");: Opens the video file for reading.
    • Checks if the file was opened successfully. If not, prints an error message and exits.
  4. Create Windows:
    • namedWindow("Original Video", WINDOW_AUTOSIZE);: Creates a window to display the original video.
    • namedWindow("Encrypted Video", WINDOW_AUTOSIZE);: Creates a window to display the encrypted video.
  5. Processing Loop:
    • Captures frames from the video and encrypts each frame using the XOR cipher.
    • Displays both the original and encrypted frames.
    • Advertisement
    • waitKey(30); waits for 30 milliseconds for a key press. If ‘q’ is pressed, the loop exits.
  6. Cleanup:
    • cap.release();: Releases the video file resource.
    • destroyAllWindows();: Closes all OpenCV windows.
Exit mobile version