-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (63 loc) · 1.71 KB
/
main.cpp
File metadata and controls
81 lines (63 loc) · 1.71 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string encryptDecrypt(string password) {
char key = 'X';
string output = password;
for (int i = 0; i < password.size(); i++) {
output[i] = password[i] ^ key;
}
return output;
}
void addPassword() {
string account, password;
cout << "Enter account name: ";
cin >> account;
cout << "Enter password: ";
cin >> password;
string encryptedPassword = encryptDecrypt(password);
ofstream file;
file.open("passwords.txt", ios::app);
file << account << " " << encryptedPassword << endl;
file.close();
cout << "Password added successfully!\n";
}
void viewPasswords() {
string account, password;
ifstream file("passwords.txt");
if (file.is_open()) {
while (file >> account >> password) {
string decryptedPassword = encryptDecrypt(password);
cout << "Account: " << account << ", Password: " << decryptedPassword << endl;
}
file.close();
} else {
cout << "No passwords found.\n";
}
}
int main() {
int choice;
do {
cout << "\nPassword Manager\n";
cout << "1. Add new password\n";
cout << "2. View passwords\n";
cout << "3. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
addPassword();
break;
case 2:
viewPasswords();
break;
case 3:
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice!\n";
}
} while (choice != 3);
return 0;
}