-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptor.cpp
More file actions
38 lines (32 loc) · 924 Bytes
/
Encryptor.cpp
File metadata and controls
38 lines (32 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "Encryptor.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool Encryptor::processFile(const string &inputFilePath, const string &outputFilePath, const string &key)
{
ifstream inputFile(inputFilePath, ios::binary);
ofstream outputFile(outputFilePath, ios::binary);
if (!inputFile.is_open() || !outputFile.is_open())
{
cerr << "Error opening files." << endl;
return false;
}
int keyIndex = 0;
int keyLength = key.length();
if (keyLength == 0)
{
cerr << "Key cannot be empty." << endl;
return false;
}
char buffer;
while (inputFile.get(buffer))
{
char encryptedChar = buffer ^ key[keyIndex];
outputFile.put(encryptedChar);
keyIndex = (keyIndex + 1) % keyLength;
}
inputFile.close();
outputFile.close();
return true;
}