-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity.cpp
More file actions
118 lines (94 loc) · 3.54 KB
/
Copy pathsecurity.cpp
File metadata and controls
118 lines (94 loc) · 3.54 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <fstream>
#include <sstream>
#include "API_v2.h"
#include "colour.cpp"
using namespace std;
void PersonLinkedList::encryptAndSaveToCSV() {
ofstream outputFile("D:/DSA_project/database/list2.csv");
if (!outputFile.is_open()) {
cerr <<RED<< "Error opening file for writing."<<RESET<<endl;
return;
}
Person* current = head;
while (current != nullptr) {
string encryptedFname = "";
for (char c : current->fname) {
encryptedFname += static_cast<char>(c + 1);
}
string encryptedLname = "";
for (char c : current->lname) {
encryptedLname += static_cast<char>(c + 1);
}
string encryptedId = "";
for (char c : current->id) {
encryptedId += static_cast<char>(c + 1);
}
string encryptedAddress = "";
for (char c : current->address) {
encryptedAddress += static_cast<char>(c + 1);
}
string encryptedAccountnumber = "";
for (char c : current->accountnumber) {
encryptedAccountnumber += static_cast<char>(c + 1);
}
string encryptedUsername = "";
for (char c : current->username) {
encryptedUsername += static_cast<char>(c + 1);
}
string encryptedPassword = "";
for (char c : current->password) {
encryptedPassword += static_cast<char>(c + 1);
}
// Save encrypted data to CSV
outputFile << encryptedFname << "," << encryptedLname << ","
<< current->age << "," << encryptedId << ","
<< encryptedAddress << "," << encryptedAccountnumber<< ","
<< encryptedUsername << "," << encryptedPassword << "," << current->amount << "\n";
current = current->next;
}
}
void PersonLinkedList::decryptAndSaveToCSV() {
ofstream outputFile("D:/DSA_project/database/list2.csv");
if (!outputFile.is_open()) {
cerr <<RED<< "Error opening file for writing."<<RESET<<endl;
return;
}
Person* current = head;
while (current != nullptr) {
string decryptedFname = "";
for (char c : current->fname) {
decryptedFname += static_cast<char>(c - 1);
}
string decryptedLname = "";
for (char c : current->lname) {
decryptedLname += static_cast<char>(c - 1);
}
string decryptedId = "";
for (char c : current->id) {
decryptedId += static_cast<char>(c - 1);
}
string decryptedAddress = "";
for (char c : current->address) {
decryptedAddress += static_cast<char>(c - 1);
}
string decryptedAccountnumber = "";
for (char c : current->accountnumber) {
decryptedAccountnumber += static_cast<char>(c - 1);
}
string decryptedUsername = "";
for (char c : current->username) {
decryptedUsername += static_cast<char>(c - 1);
}
string decryptedPassword = "";
for (char c : current->password) {
decryptedPassword += static_cast<char>(c - 1);
}
// Save decrypted data to CSV
outputFile << decryptedFname << "," << decryptedLname << ","
<< current->age << "," << decryptedId << ","
<< decryptedAddress << "," << decryptedAccountnumber << ","
<< decryptedUsername << "," << decryptedPassword << "," << current->amount << "\n";
current = current->next;
}
}