-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f35c61
commit 6835555
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
class PasswordManager { | ||
private: | ||
std::string username; | ||
std::string password; | ||
int shift = 3; // Shift value for Caesar cipher | ||
|
||
std::string encrypt(const std::string& text) { | ||
std::string encrypted_text; | ||
for (char c : text) { | ||
if (isalpha(c)) { | ||
char base = isupper(c) ? 'A' : 'a'; | ||
c = ((c - base + shift) % 26) + base; | ||
} | ||
encrypted_text += c; | ||
} | ||
return encrypted_text; | ||
} | ||
|
||
std::string decrypt(const std::string& text) { | ||
std::string decrypted_text; | ||
for (char c : text) { | ||
if (isalpha(c)) { | ||
char base = isupper(c) ? 'A' : 'a'; | ||
c = ((c - base - shift + 26) % 26) + base; | ||
} | ||
decrypted_text += c; | ||
} | ||
return decrypted_text; | ||
} | ||
|
||
public: | ||
void setData(std::string username, std::string password) { | ||
this->username = username; | ||
this->password = password; | ||
} | ||
|
||
void saveToFile(std::string fileName) { | ||
std::ofstream file; | ||
file.open(fileName); | ||
if (file.is_open()) { | ||
file << encrypt(username) << "\n" << encrypt(password); | ||
file.close(); | ||
} else { | ||
std::cout << "Unable to open file for writing.\n"; | ||
} | ||
} | ||
|
||
void readFromFile(std::string fileName) { | ||
std::ifstream file; | ||
file.open(fileName); | ||
if (file.is_open()) { | ||
std::getline(file, username); | ||
std::getline(file, password); | ||
file.close(); | ||
username = decrypt(username); | ||
password = decrypt(password); | ||
std::cout << "Username: " << username << "\nPassword: " << password << "\n"; | ||
} else { | ||
std::cout << "Unable to open file for reading.\n"; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
|
||
class PasswordManager { | ||
private: | ||
std::string username; | ||
std::string password; | ||
|
||
public: | ||
void setData(std::string username, std::string password) { | ||
this->username = username; | ||
this->password = password; | ||
} | ||
|
||
void saveToFile(std::string fileName) { | ||
std::ofstream file; | ||
file.open(fileName); | ||
if (file.is_open()) { | ||
file << username << "\n" << password; | ||
file.close(); | ||
} else { | ||
std::cout << "Unable to open file for writing.\n"; | ||
} | ||
} | ||
|
||
void readFromFile(std::string fileName) { | ||
std::ifstream file; | ||
file.open(fileName); | ||
if (file.is_open()) { | ||
std::getline(file, username); | ||
std::getline(file, password); | ||
file.close(); | ||
std::cout << "Username: " << username << "\nPassword: " << password << "\n"; | ||
} else { | ||
std::cout << "Unable to open file for reading.\n"; | ||
} | ||
} | ||
}; |