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>
- using namespace std;
- //Объявляем массив символов русского и английского алфавита
- string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
- string alphabuf = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
- int code(char str)
- {
- for (int i = 0; i < 33; i++) {
- if (str == alpha[i])
- return i;
- }
- }
- int main() {
- system("chcp 1251");
- system("cls");
- setlocale(LC_ALL, "Russian");
- ifstream keys("key.txt");
- ifstream start("start.txt");
- ofstream output("out.txt");
- char alphaB[30][2] = { ' ' };
- 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 >= 'а') && (buf <= 'я'))
- {
- for (int i = 0; i <= keybuf.length(); ++i)
- {
- if (keybuf[i] == buf)
- check = 1;
- }
- if (check == 0)
- {
- keybuf += buf;
- check = 0;
- }
- }
- }
- cout << keybuf;
- for (int i = 0; i < keybuf.length(); ++i)
- {
- for (int j = 0; j < alphabuf.length(); ++j)
- {
- if (keybuf[i] == alphabuf[j])
- {
- alphabuf.erase(j, 1);
- break;
- }
- }
- }
- keybuf += alphabuf;
- cout << endl << alphabuf;
- cout << endl << alpha << endl << keybuf << endl;
- cout << message;
- while (!start.eof()) {
- char buf;
- start >> buf;
- message.erase(0, 1);
- for (int i = 0; i < alpha.length(); ++i)
- {
- if (buf == alpha[i]) crypt += keybuf[i];
- }
- }
- crypt.erase(crypt.length()-1, 1);
- cout << crypt;
- while (!crypt.empty())
- {
- char buf;
- buf = crypt[0];
- crypt.erase(0, 1);
- for (int i = 0; i < alpha.length(); ++i)
- {
- if (buf == keybuf[i]) message += alpha[i];
- }
- }
- cout << endl << message << endl;;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment