-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (45 loc) · 1.21 KB
/
main.cpp
File metadata and controls
55 lines (45 loc) · 1.21 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <fstream>
using namespace std;
// Function to encrypt or decrypt file
void processFile(const string &inputFile, const string &outputFile, const string &key)
{
ifstream in(inputFile, ios::binary);
ofstream out(outputFile, ios::binary);
if (!in.is_open() || !out.is_open())
{
cerr << "Error: Could not open input/output files.\n";
return;
}
char buffer;
size_t keyLength = key.length();
size_t i = 0;
while (in.get(buffer))
{
char encryptedChar = buffer ^ key[i % keyLength]; // XOR with key
out.put(encryptedChar);
i++;
}
in.close();
out.close();
cout << "✅ Processing completed.\n";
}
int main()
{
string inputFile, outputFile, key;
int choice;
cout << "====== File Encryptor/Decryptor ======\n";
cout << "1. Encrypt File\n";
cout << "2. Decrypt File\n";
cout << "Choose option (1/2): ";
cin >> choice;
cin.ignore();
cout << "Enter input file path: ";
getline(cin, inputFile);
cout << "Enter output file path: ";
getline(cin, outputFile);
cout << "Enter secret key: ";
getline(cin, key);
processFile(inputFile, outputFile, key);
return 0;
}