-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfiletransfer.cpp
More file actions
35 lines (35 loc) · 916 Bytes
/
filetransfer.cpp
File metadata and controls
35 lines (35 loc) · 916 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
#include <iostream>
#include <fstream>
using namespace std;
void encryptAndWrite(string message){
ofstream outFile("data.txt");
for(int i=0; i<message.length(); i++){
message[i]=message[i]+3;
}
outFile<<message;
outFile.close();
cout<<"Message encrypted and stored in the file\n";
}
string readAndDecrypt(){
ifstream inFile("data.txt");
string message;
getline(inFile, message);
inFile.close();
for(int i = 0; i<message.length(); i++){
message[i]=message[i]-3;
}
return message;
}
void displayFileContents(){
string decryptedMessage=readAndDecrypt();
cout<<"Decrypted Message:"<<decryptedMessage<<"\n";
}
int main(){
string message;
cout<<"Enter data:";
getline(cin, message);
encryptAndWrite(message);
cout<<"Reading and decrypting file\n";
displayFileContents();
return 0;
}