ademosh

1 безопасность 2к19

Oct 21st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include "pch.h"
  2. #include <string.h>
  3. #include <fstream>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char mess[1000];
  10. char messb[1000];
  11. char alpha[] = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
  12. char alphaB[] = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЫЭЮЯ";
  13. char assist[] = " .,-:;^123456789!?";
  14. int alphabeg = strlen(alpha);
  15. char codealpha[100];
  16. char codealphaB[100];
  17. system("chcp 1251");
  18. system("cls");
  19. int zeronumb;
  20. bool mode = 1;
  21. bool zeroexists = 1;
  22. int n = 4, k = 4;
  23. int nr;
  24. int target = 0;
  25. ofstream fout("end.txt");
  26. ifstream start("start.txt");
  27. while (!start.eof())
  28. {
  29. char buf;
  30. start.get(messb[target]);
  31. target++;
  32.  
  33. }
  34. for (int i = 0; i < target - 1; ++i)
  35. {
  36. mess[i] = messb[i];
  37. }
  38. target--;
  39. int length = target;
  40. if (alphabeg%n == 0) { cout << "Error, wrong A key"; }
  41. else
  42. {
  43. for (int i = 2; i < 1000; ++i)
  44. {
  45. if (((i*n) % alphabeg) == 1) { nr = i; break; }
  46. }
  47. if (mode == 0)
  48. {
  49. for (int i = 0; i < length; ++i)
  50. {
  51. bool prep = 0;
  52. int prepn = 0;
  53. for (int t = 0; t < strlen(assist); ++t)
  54. {
  55. if (mess[i] == assist[t])
  56. {
  57. prep = 1;
  58. prepn = t;
  59. }
  60. }
  61. if (!prep)
  62. {
  63. for (int j = 0; j < alphabeg; ++j)
  64. {
  65. if (mess[i] == alpha[j]) {
  66. int code = 0;
  67. code = ((n*j + k) % alphabeg);
  68. fout << alpha[code];
  69. }
  70. else
  71. if (mess[i] == alphaB[j])
  72. {
  73. int code = 0;
  74. code = ((n*j + k) % alphabeg);
  75. fout << alphaB[code];
  76. }
  77. }
  78. }
  79. else
  80. fout << assist[prepn];
  81. }
  82. }
  83. else
  84. {
  85. for (int i = 0; i < length; ++i)
  86. {
  87. bool prep = 0;
  88. int prepn = 0;
  89. for (int t = 0; t < strlen(assist); ++t)
  90. {
  91. if (mess[i] == assist[t])
  92. {
  93. prep = 1;
  94. prepn = t;
  95. }
  96. }
  97. if (!prep)
  98. {
  99. for (int j = 0; j < alphabeg; ++j)
  100. {
  101. if (mess[i] == alpha[j]) {
  102. int code = 0;
  103. code = (nr*(j + alphabeg - k) % (alphabeg));
  104. fout << alpha[code];
  105. }
  106. else
  107. if (mess[i] == alphaB[j])
  108. {
  109. int code = 0;
  110. code = (nr*(j + alphabeg - k) % (alphabeg));
  111. fout << alphaB[code];
  112. }
  113. }
  114. }
  115. else
  116. fout << assist[prepn];
  117. }
  118. }
  119. }
  120. system("pause");
  121. fout.close();
  122. return 0;
  123. }
Add Comment
Please, Sign In to add comment