Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <iostream>
- #include <ctype.h>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- //Объявляем массив символов русского и английского алфавита
- string alpha = "abcdefghijklmnopqrstuvwxyz";
- string numb = "0123456789";
- int main() {
- srand(time(NULL));
- ifstream keys("key.txt");
- ifstream start("start.txt");
- ofstream output("out.txt");
- string message;
- string key;
- string keybuf;
- string crypt;
- cout << endl;
- while (!keys.eof())
- {
- char buf;
- bool check = 0;
- keys >> buf;
- buf = tolower(buf);
- if ((buf >= 'a') && (buf <= 'z'))
- {
- for (int i = 0; i <= keybuf.length(); ++i)
- {
- if (keybuf[i] == buf)
- check = 1;
- }
- if (check == 0)
- {
- keybuf += buf;
- check = 0;
- }
- }
- }
- cout << keybuf << endl;
- if (keybuf.length() < 8) cout << "Wrong key" << endl;
- else {
- string first;
- string second;
- string third;
- int ukazi = 0;
- int ukazj = 0;
- cout << keybuf.length() << endl;
- if (keybuf.length() > 9) keybuf.erase(9, 100);
- first = keybuf;
- for (int i = 0; i < 26; ++i)
- {
- bool check = 0;
- for (int j = 0; j < keybuf.length(); ++j)
- {
- if (keybuf[j] == alpha[i]) check = 1;
- }
- if (check == 0) {
- if (second.length() < 9) {
- second += alpha[i];
- }
- else {
- third += alpha[i];
- }
- }
- }
- cout << first << endl << second << endl << third << endl;
- bool mode;
- cin >> mode;
- if (mode == 0) {
- string crypt;
- while (!start.eof()) {
- char buf;
- start >> buf;
- buf = tolower(buf);
- int nfirst = first.find(buf, 0);
- if (nfirst > 0) {
- int f = rand() % 6 + 4;
- crypt += numb[f];
- crypt += numb[nfirst + 1];
- }
- else {
- int nsecond = second.find(buf, 0);
- if (nsecond > 0) {
- int f = rand() % 2 + 2;
- crypt += numb[f];
- crypt += numb[nsecond + 1];
- }
- else{
- int nthird = third.find(buf, 0);
- if (nthird > 0) {
- crypt += numb[1];
- crypt += numb[nthird + 1];
- }
- }
- }
- }
- crypt.erase(crypt.length() - 2, 10);
- srand(time(NULL));
- int random = rand() % crypt.length();
- for (int i = 0; i < random; ++i)
- {
- int randplace = rand() % crypt.length();
- crypt.insert(randplace, "0");
- }
- cout << endl << crypt << endl;
- output << crypt;
- }
- else {
- cout << "Open text is: " << endl;
- string bufs;
- while (!start.eof()) {
- char buf;
- start >> buf;
- buf = tolower(buf);
- if (buf != '0') bufs += buf;
- if (bufs.length() == 2) {
- int n2 = numb.find(bufs[1], 0);
- int n1 = numb.find(bufs[0], 0);
- n2 -= 1;
- if ((n1 <= 9) && (n1 >= 4))
- cout << first[n2];
- else
- if (n1 == 1)
- cout << third[n2];
- else cout << second[n2];
- bufs.erase(0, 2);
- }
- }
- cout << endl;
- }
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment