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[20][2];
- string message;
- string over={""};
- string key;
- string decode;
- getline(start, key);
- getline(start, message);
- int o;
- int ukazi = 0;
- int ukazj = 0;
- for (int i = 0; i < message.length(); ++i) {
- int buf;
- buf = (code(message[i]) + code(key[i%key.length()]));
- if (buf >= 33) {
- over += '1';
- buf = buf % 33;
- }
- else over += '0';
- buf = buf % 33;
- cout << endl << code(message[i]) << ' ' << code(key[i%key.length()])<<' '<<buf;
- decode += alpha[buf];
- }
- cout << endl;
- cout << decode;
- cout << endl;
- for (int i = 0; i < message.length(); ++i)
- {
- int buf;
- int codeb= code(decode[i]);
- if (over[i] == '1') codeb += 33;
- buf = abs((codeb - code(key[i%key.length()]) )% 33);
- cout << endl << codeb << ' ' << code(key[i%key.length()]) << ' ' << buf;
- cout << alpha[buf];
- output << alpha[buf];
- }
- cout << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment