#include <Windows.h>
#include <iostream>
#include <fstream>
#include <string>
void XORCrypt(char* data, int size, const std::string& key) {int keyLength = key.length();for (int i = 0; i < size; ++i) {data[i] = data[i] ^ key[i % keyLength]; }
}
void EncryptFile(const std::string& inputFileName, const std::string& outputFileName, const std::string& key) {std::ifstream inputFile(inputFileName, std::ios::binary);if (!inputFile.is_open()) {std::cerr << "Error: Unable to open input file." << std::endl;return;}inputFile.seekg(0, std::ios::end);int fileSize = inputFile.tellg();inputFile.seekg(0, std::ios::beg);char* buffer = new char[fileSize];if (!buffer) {std::cerr << "Error: Memory allocation failed." << std::endl;inputFile.close();return;}inputFile.read(buffer, fileSize);inputFile.close();XORCrypt(buffer, fileSize, key);std::ofstream outputFile(outputFileName, std::ios::binary);if (!outputFile.is_open()) {std::cerr << "Error: Unable to open output file." << std::endl;delete[] buffer;return;}outputFile.write(buffer, fileSize);outputFile.close();delete[] buffer;std::cout << "Encryption completed successfully." << std::endl;
}int main() {std::string inputFileName; std::string outputFileName; std::string key; std::cout << "Enter input file name: ";std::getline(std::cin, inputFileName);std::cout << "Enter output file name: ";std::getline(std::cin, outputFileName);std::cout << "Enter encryption key: ";std::getline(std::cin, key);EncryptFile(inputFileName, outputFileName, key);system("pause");return 0;
}