ademosh

13 безопасность

Nov 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include "pch.h"
  2. #include <fstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iostream>
  6.  
  7.  
  8.  
  9. using namespace std;
  10. //Объявляем массив символов русского и английского алфавита
  11. string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя,-.";
  12. int code(char str)
  13. {
  14. for (int i = 0; i < 33; i++) {
  15. if (str == alpha[i])
  16. return i;
  17. }
  18. }
  19.  
  20. unsigned short lfsr = 0xACE1u;
  21. unsigned bit;
  22. unsigned period = 0;
  23.  
  24. int main() {
  25. system("chcp 1251");
  26. system("cls");
  27. setlocale(LC_ALL, "Russian");
  28. ifstream start("start.txt");
  29. ofstream output("out.txt");
  30. char alphaB[30][2] = { ' ' };
  31. string message;
  32. int keym[10];
  33. string keybuf;
  34. string key;
  35. getline(start, key);
  36. getline(start, message);
  37. cout << endl;
  38. int o;
  39. int ukazi = 0;
  40. int ukazj = 0;
  41. int A = 43;
  42. int C = 6;
  43. keym[0] = code(key[0]);
  44. for (int i = 1; i < 10; ++i)
  45. {
  46. int buf;
  47. buf = (A*keym[i - 1] + C) % 33;
  48. keym[i] = buf % 33;
  49. }
  50. string decode;
  51. for (int i = 0; i < message.length(); ++i) {
  52. char buf = (message[i] ^ keym[i % 10]);
  53. output << buf << ' ';
  54. decode += buf;
  55. }
  56.  
  57. cout << endl << decode << endl;
  58. for (int i = 0; i < decode.length(); ++i) {
  59. char buf = (decode[i] ^ keym[i % 10]);
  60. cout << buf;
  61. }
  62. cout << endl;
  63. system("pause");
  64. return 0;
  65. }
Add Comment
Please, Sign In to add comment