Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <math.h>
  4. #include <vector>
  5. #include <windows.h>
  6. #include <random>
  7. #include <time.h>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. cout << "Enter your message: ";
  14. string msg;
  15. cin >> msg;
  16. cout << msg << '\n';
  17. int cipherSize = msg.size() * 3;
  18. int n = sqrt(cipherSize);
  19. int m = cipherSize / n;
  20. if (cipherSize % n)
  21. m++;
  22. vector < vector <bool> > siele(n, vector <bool>(m, 1));
  23. vector < vector <char> > sifer(n, vector <char>(m));
  24.  
  25. int holes = 0;
  26. while (holes < msg.size()) {
  27. srand(time(0));
  28. int i = rand() % n;
  29. int j = rand() % m;
  30. if (siele[i][j] == 0)
  31. continue;
  32. siele[i][j] = 0;
  33. holes++;
  34. }
  35.  
  36. cout << '\n';
  37. for (int i = 0; i < n; i++) {
  38. for (int j = 0; j < m; j++)
  39. cout << siele[i][j] << ' ';
  40. cout << '\n';
  41. }
  42.  
  43. int cnt = 0;
  44. string siferMsg = "";
  45. for (int i = 0; i < n; i++) {
  46. for (int j = 0; j < m; j++) {
  47. if (siele[i][j] == 0) {
  48. sifer[i][j] = msg[cnt];
  49. cnt++;
  50. }
  51. else {
  52. bool coin = rand() % 1;
  53. if (coin)
  54. sifer[i][j] = (char)rand() % 26 + 65;
  55. else
  56. sifer[i][j] = (char)rand() % 26 + 97;
  57. }
  58. siferMsg += sifer[i][j];
  59. }
  60. }
  61.  
  62. cout << '\n';
  63. for (int i = 0; i < n; i++) {
  64. for (int j = 0; j < m; j++)
  65. cout << sifer[i][j] << ' ';
  66. cout << '\n';
  67. }
  68.  
  69. cout << '\n' << "Your sifer: " << siferMsg << '\n';
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement