Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <cassert>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long li;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define pb push_back
- #define mp make_pair
- #define all(v) v.begin(),v.end()
- #define EPS 1e-9
- #define PI 3.1415926535897932384626433832795
- int gcd (int a, int b) {
- return b ? gcd (b, a % b) : a;
- }
- int main() {
- srand(time(NULL));
- ifstream key_stream("key.txt");
- ifstream text_stream("text.txt");
- freopen("output.txt", "w", stdout);
- string alph = "абвгдежзийклмнопрстуфхцчшщъыьэюя0123456789.,!?";
- map <char, int> pos;
- forn (i, alph.size())
- pos[alph[i]] = i;
- int n, m = alph.size(), k;
- key_stream >> n >> k;
- if (gcd(n, m) != 1 || n < m) {
- cout << "incorrect key" << endl;
- return 0;
- }
- while (!text_stream.eof()) {
- string text_temp;
- text_stream >> text_temp;
- forn (i, text_temp.size()) {
- if (text_temp[i] >= 'А' && text_temp[i] <= 'Я')
- text_temp[i] += 'а' - 'А';
- cout << alph[(pos[text_temp[i]] * n + k) % m];
- }
- }
- return 0;
- }
- ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <set>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <cassert>
- #include <queue>
- #include <fstream>
- using namespace std;
- typedef long long li;
- typedef long double ld;
- #define forn(i, n) for (int i = 0; i < int(n); ++i)
- #define pb push_back
- #define mp make_pair
- #define all(v) v.begin(),v.end()
- #define EPS 1e-9
- #define PI 3.1415926535897932384626433832795
- int gcd (int a, int b) {
- return b ? gcd (b, a % b) : a;
- }
- int main() {
- srand(time(NULL));
- ifstream key_stream("key.txt");
- ifstream text_stream("text.txt");
- freopen("output.txt", "w", stdout);
- string alph = "абвгдежзийклмнопрстуфхцчшщъыьэюя0123456789.,!?";
- map <char, int> pos;
- forn (i, alph.size())
- pos[alph[i]] = i;
- int n, m = alph.size(), k;
- key_stream >> n >> k;
- if (gcd(n, m) != 1) {
- cout << "НОД(n, m) != 1" << endl;
- return 0;
- }
- string text;
- text_stream >> text;
- forn (i, text.size()) {
- int y = pos[text[i]];
- int x = (n * n * (y - k)) % m;
- cout << alph[x];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement