Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <math.h>
- #include <vector>
- #include <windows.h>
- #include <random>
- #include <time.h>
- using namespace std;
- int main()
- {
- cout << "Enter your message: ";
- string msg;
- cin >> msg;
- cout << msg << '\n';
- int cipherSize = msg.size() * 3;
- int n = sqrt(cipherSize);
- int m = cipherSize / n;
- if (cipherSize % n)
- m++;
- vector < vector <bool> > siele(n, vector <bool>(m, 1));
- vector < vector <char> > sifer(n, vector <char>(m));
- int holes = 0;
- while (holes < msg.size()) {
- srand(time(0));
- int i = rand() % n;
- int j = rand() % m;
- if (siele[i][j] == 0)
- continue;
- siele[i][j] = 0;
- holes++;
- }
- cout << '\n';
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++)
- cout << siele[i][j] << ' ';
- cout << '\n';
- }
- int cnt = 0;
- string siferMsg = "";
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (siele[i][j] == 0) {
- sifer[i][j] = msg[cnt];
- cnt++;
- }
- else {
- bool coin = rand() % 1;
- if (coin)
- sifer[i][j] = (char)rand() % 26 + 65;
- else
- sifer[i][j] = (char)rand() % 26 + 97;
- }
- siferMsg += sifer[i][j];
- }
- }
- cout << '\n';
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++)
- cout << sifer[i][j] << ' ';
- cout << '\n';
- }
- cout << '\n' << "Your sifer: " << siferMsg << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement