Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <iostream>
- #include <ctype.h>
- using namespace std;
- //Объявляем массив символов русского и английского алфавита
- string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
- int main() {
- system("chcp 1251");
- system("cls");
- setlocale(LC_ALL, "Russian");
- ifstream keys("key.txt");
- ifstream start("start.txt");
- ofstream output("out.txt");
- string message;
- string key;
- string keybuf;
- string crypt;
- 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 < alpha.length(); ++i)
- {
- bool check = 0;
- for (int j = 0; j < keybuf.length(); j++)
- {
- if (alpha[i] == keybuf[j]) check = 1;
- }
- if (check == 0) keybuf += alpha[i];
- }
- cout << endl << alpha << endl << keybuf << endl;
- bool mode;
- cout << "Введите 0 для шифровки сообщения или 1 для дешифровки сообщения" << endl;
- cin >> mode;
- if (mode == 0) {
- while (!start.eof()) {
- char buf;
- start >> buf;
- buf = tolower(buf);
- bool symb = 0;
- for (int i = 0; i < alpha.length(); ++i)
- {
- if (buf == alpha[i])
- {
- crypt += keybuf[i];
- }
- }
- }
- crypt.erase(crypt.length() - 1, 1);
- cout << "Криптограмма: " << crypt;
- output << crypt;
- }
- else
- {
- while (!start.eof())
- {
- char buf;
- bool symb = 0;
- start >> buf;
- buf = tolower(buf);
- for (int i = 0; i < alpha.length(); ++i)
- {
- if (buf == keybuf[i])
- {
- message += alpha[i];
- }
- }
- }
- message.erase(message.length() - 1, 1);
- cout << endl << "Изначальное сообщение: " << message << endl;
- output << message;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement