Created
May 30, 2023 18:56
-
-
Save ilfey/6e5d9a6fdee33f1a5ec7339b757866ca to your computer and use it in GitHub Desktop.
main.cpp
This file contains hidden or 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
| #include <iostream> | |
| #include <fstream> | |
| #include <string> | |
| using namespace std; | |
| void encrypt() | |
| { | |
| ifstream fin("input.txt"); | |
| if (fin.is_open()) | |
| { | |
| string line; | |
| ofstream fout; | |
| fout.open("output.txt"); | |
| if (fout.is_open()) | |
| { | |
| while (getline(fin, line)) | |
| { | |
| for (auto i : line) | |
| { | |
| if (i == ' ') | |
| { | |
| fout << endl; | |
| } | |
| else | |
| { | |
| fout << i << ','; | |
| } | |
| } | |
| fout << endl | |
| << ',' | |
| << endl; | |
| } | |
| fout.close(); | |
| } | |
| fin.close(); | |
| } | |
| } | |
| void decrypt() | |
| { | |
| ifstream fin("output.txt"); | |
| if (fin.is_open()) | |
| { | |
| string line; | |
| while (getline(fin, line)) | |
| { | |
| if (line.length() == 1) | |
| { | |
| cout << endl; | |
| continue; | |
| } | |
| int c = -1; | |
| for (auto i : line) | |
| { | |
| c++; | |
| if (i != ',') | |
| { | |
| cout << i; | |
| continue; | |
| } | |
| if (line[c - 1] == ',' && line[c - 2] != ',') | |
| { | |
| cout << ','; | |
| } | |
| } | |
| cout << ' '; | |
| } | |
| fin.close(); | |
| } | |
| } | |
| int main() | |
| { | |
| string action = ""; | |
| cout << "Encrypt? (Y/n) >>> "; | |
| getline(cin, action); | |
| if (action != "n") | |
| { | |
| encrypt(); | |
| } | |
| else | |
| { | |
| decrypt(); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment