Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <string.h>
- #include <fstream>
- #include <iostream>
- using namespace std;
- int main()
- {
- char mess[1000];
- char messb[1000];
- char alpha[] = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
- char alphaB[] = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЫЭЮЯ";
- char assist[] = " .,-:;^123456789!?";
- int alphabeg = strlen(alpha);
- char codealpha[100];
- char codealphaB[100];
- system("chcp 1251");
- system("cls");
- int zeronumb;
- bool mode = 1;
- bool zeroexists = 1;
- int n = 4, k = 4;
- int nr;
- int target = 0;
- ofstream fout("end.txt");
- ifstream start("start.txt");
- while (!start.eof())
- {
- char buf;
- start.get(messb[target]);
- target++;
- }
- for (int i = 0; i < target - 1; ++i)
- {
- mess[i] = messb[i];
- }
- target--;
- int length = target;
- if (alphabeg%n == 0) { cout << "Error, wrong A key"; }
- else
- {
- for (int i = 2; i < 1000; ++i)
- {
- if (((i*n) % alphabeg) == 1) { nr = i; break; }
- }
- if (mode == 0)
- {
- for (int i = 0; i < length; ++i)
- {
- bool prep = 0;
- int prepn = 0;
- for (int t = 0; t < strlen(assist); ++t)
- {
- if (mess[i] == assist[t])
- {
- prep = 1;
- prepn = t;
- }
- }
- if (!prep)
- {
- for (int j = 0; j < alphabeg; ++j)
- {
- if (mess[i] == alpha[j]) {
- int code = 0;
- code = ((n*j + k) % alphabeg);
- fout << alpha[code];
- }
- else
- if (mess[i] == alphaB[j])
- {
- int code = 0;
- code = ((n*j + k) % alphabeg);
- fout << alphaB[code];
- }
- }
- }
- else
- fout << assist[prepn];
- }
- }
- else
- {
- for (int i = 0; i < length; ++i)
- {
- bool prep = 0;
- int prepn = 0;
- for (int t = 0; t < strlen(assist); ++t)
- {
- if (mess[i] == assist[t])
- {
- prep = 1;
- prepn = t;
- }
- }
- if (!prep)
- {
- for (int j = 0; j < alphabeg; ++j)
- {
- if (mess[i] == alpha[j]) {
- int code = 0;
- code = (nr*(j + alphabeg - k) % (alphabeg));
- fout << alpha[code];
- }
- else
- if (mess[i] == alphaB[j])
- {
- int code = 0;
- code = (nr*(j + alphabeg - k) % (alphabeg));
- fout << alphaB[code];
- }
- }
- }
- else
- fout << assist[prepn];
- }
- }
- }
- system("pause");
- fout.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment