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");
- string alphaB[33][33] = { "" };
- for (int i = 0; i < 33; ++i)
- {
- int j = 0;
- int shift = i;
- cout << shift << endl;
- while (j < 33)
- {
- if (shift == 33) shift -= 33;
- alphaB[i][j] = alpha[shift];
- shift++;
- j++;
- }
- }
- for (int i = 0; i < 33; ++i)
- {
- for (int j = 0; j < 33; ++j)
- cout << alphaB[i][j] << ' ';
- cout << endl;
- }
- string message;
- string key ;
- getline(start, key);
- getline(start, message);
- cout << endl;
- int o;
- cin >> o;
- if (o == 0)
- {
- int k = 0;
- int cod;
- int resultcode = 0;
- string out;
- for (int i = 0; i < message.length(); i += 1)
- {
- if (k >= key.length())
- k = 0;
- resultcode += code(message[i]);
- resultcode += code(key[k]);
- //if (resultcode >= 66) resultcode -= 33;
- //if (resultcode >= 66) resultcode -= 33;
- int stroka = abs(code(message[i]));
- int stolb = abs(code(key[k]));
- cout << message[i] << ' ' << stroka << ' ' << stolb << ' ' << endl;
- output << alphaB[stroka][stolb];
- resultcode = 0;
- k++;
- }
- }
- if (o == 1)
- {
- int k = 0;
- int cod;
- int resultcode = 0;
- string out;
- for (int i = 0; i < message.length(); i += 1)
- {
- if (k >= key.length())
- k = 0;
- resultcode += code(message[i]);
- resultcode += code(key[k]);
- //if (resultcode >= 66) resultcode -= 33;
- //if (resultcode >= 66) resultcode -= 33;
- int stroka = abs(code(message[i]));
- int stolb = abs(code(key[k]));
- for (int j = 0; j < 32; ++j)
- {
- if (alphaB[j][stolb] == alphaB[code(message[i])][0]) {
- cout << j << ' ' << stolb << ' ' << code(message[i]) << alphaB[j][stolb]<<' '<< endl;
- output << alphaB[j][0];
- break;
- }
- }
- resultcode = 0;
- k++;
- }
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment