ademosh

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

Nov 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 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. //for (int i = 0; i < 100000; ++i)
  42. //cout << <<endl;
  43. uint16_t start_state = 0xACE1u; /* Any nonzero start state will work. */
  44. uint16_t lfsr = 1;
  45. while (!key.empty()) {
  46. lfsr*=code(key[0]);
  47. key.erase(0,1);
  48. }
  49. uint16_t bit; /* Must be 16bit to allow bit<<15 later in the code */
  50. for (int i = 0; i < 10; ++i)
  51. {
  52. while (lfsr != rand()) {
  53. bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5)) & 1;
  54. lfsr = (lfsr >> 1) | (bit << 15);
  55. ++period;
  56. }
  57. cout << period%33<<endl;
  58. keym[i] = period % 33;
  59. }
  60. string decode;
  61. for (int i = 0; i < message.length(); ++i) {
  62. char buf = (message[i] ^ keym[i%10]);
  63. output << buf << ' ';
  64. decode += buf;
  65. }
  66.  
  67. cout << endl << decode<<endl;
  68. for (int i = 0; i < decode.length(); ++i) {
  69. char buf = (decode[i] ^ keym[i%10]);
  70. cout << buf ;
  71. }
  72. cout << endl;
  73. system("pause");
  74. return 0;
  75. }
Add Comment
Please, Sign In to add comment