Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- bool encryptChar(char _c)
- {
- return !(_c == ' ' || _c == ',' || _c == '.' || _c == '?' || _c == '!' || _c == ':' || _c == ';' || _c == '(' || _c == ')');
- }
- char cipher(char _c, int _shift)
- {
- if(encryptChar(_c)) return (char)(_c + _shift);
- else return _c;
- }
- string properFile(string _fileName, string _content, int _shift)
- {
- fstream file;
- file.open(_fileName + ".txt", ios::in);
- if(file.good())
- {
- vector <string> lines;
- string temp;
- cout << "Poprawnie otworzono plik" << endl;
- cout << "Trwa odczytywanie danych z pliku..." << endl;
- while(!file.eof())
- {
- getline(file, temp);
- lines.push_back(temp);
- }
- cout << "Trwa kodowanie..." << endl;
- for (int k = 0; k < lines.size(); ++k)
- {
- for (int j = 0; j < lines[k].length(); ++j)
- {
- lines[k][j] = cipher(lines[k][j], _shift);
- //cout << lines[k][j] << ">" << cipher(lines[k][j], _shift) << "\t"; //
- }
- }
- for (const string line : lines)
- {
- _content += line + "\n";
- }
- cout << "Kodowanie zakonczone!" << endl;
- }
- else cout << "Blad podczas otwierania pliku" << endl;
- file.flush();
- file.close();
- return _content;
- }
- void saveEncryptedToFile(string _endFile, string _content)
- {
- fstream file;
- file.open(_endFile + ".txt", ios::out);
- file << _content;
- file.close();
- }
- int main()
- {
- const int shift = 3;
- string content, fileName, endFile;
- cout << "Podaj nazwe pliku(bez rozszerzenia), ktore zawartosc chcesz zakodowac: ";
- cin >> fileName;
- content = properFile(fileName, content, shift);
- //cout << content <<endl;
- endFile = fileName+"_Encrypted";
- saveEncryptedToFile(endFile, content);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement