Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- //Объявляем массив символов русского и английского алфавита
- string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя,-.";
- 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 start("start.txt");
- ofstream output("out.txt");
- char alphaB[6][6] ;
- string message;
- string key ;
- getline(start, key);
- getline(start, message);
- cout << endl;
- int o;
- int ukazi = 0;
- int ukazj = 0;
- while (key.length()>0)
- {
- char buf = key[0];
- key.erase(0, 1);
- alpha.erase(code(buf), 1);
- alphaB[ukazi][ukazj] = buf;
- ukazj += 1;
- if (ukazj == 6) {
- ukazj = 0;
- ukazi += 1;
- }
- }
- while (alpha.length() > 0)
- {
- char buf = alpha[0];
- alpha.erase(0, 1);
- alphaB[ukazi][ukazj] = buf;
- ukazj += 1;
- if (ukazj == 6) {
- ukazj = 0;
- ukazi += 1;
- }
- }
- for (int i = 0; i < 6; ++i) {
- for (int j = 0; j < 6; ++j) {
- cout << alphaB[i][j] << ' ';
- }
- cout << endl;
- }
- cin >> o;
- if (o==0)
- {
- string first;
- string second;
- for (int i = 0; i < message.length(); ++i)
- {
- for (int im = 0; im < 6; ++im)
- for (int jm = 0; jm < 6; ++jm) {
- if (message[i] == alphaB[im][jm]) {
- auto f = to_string(im);
- auto s = to_string(jm);
- first += f;
- second += s;
- }
- }
- }
- cout << first << endl << second;
- first += second;
- while (!first.empty())
- {
- int stroka = (int)first[0] - '0';
- first.erase(0, 1);
- int stolb = (int)first[0] - '0';
- first.erase(0, 1);
- output << alphaB[stroka][stolb];
- }
- }
- if (o == 1)
- {
- string buf;
- string first;
- string second;
- for (int i = 0; i < message.length(); ++i)
- {
- for (int im = 0; im < 6; ++im)
- for (int jm = 0; jm < 6; ++jm) {
- if (message[i] == alphaB[im][jm]) {
- auto f = to_string(im);
- auto s = to_string(jm);
- buf += f;
- buf += s;
- }
- }
- }
- int count = buf.length();
- count = count/ 2;
- for(int i=0;i<count;++i) {
- first += buf[0];
- buf.erase(0, 1);
- }
- for (int i = 0; i < count; ++i) {
- second += buf[0];
- buf.erase(0, 1);
- }
- while (!first.empty()) {
- int stroka = (int)first[0] - '0';
- first.erase(0, 1);
- int stolb = (int)second[0] - '0';
- second.erase(0, 1);
- output << alphaB[stroka][stolb];
- }
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment