Skip to content

Instantly share code, notes, and snippets.

@ilfey
Created May 30, 2023 18:56
Show Gist options
  • Select an option

  • Save ilfey/6e5d9a6fdee33f1a5ec7339b757866ca to your computer and use it in GitHub Desktop.

Select an option

Save ilfey/6e5d9a6fdee33f1a5ec7339b757866ca to your computer and use it in GitHub Desktop.
main.cpp
#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