ademosh

7 задание безопасность (???) 2к19

Oct 21st, 2019
79
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 <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. int main() {
  21. system("chcp 1251");
  22. system("cls");
  23. setlocale(LC_ALL, "Russian");
  24. ifstream start("start.txt");
  25. ofstream output("out.txt");
  26. char alphaB[20][2];
  27. string message;
  28. string over={""};
  29. string key;
  30. string decode;
  31. getline(start, key);
  32. getline(start, message);
  33. int o;
  34. int ukazi = 0;
  35. int ukazj = 0;
  36. for (int i = 0; i < message.length(); ++i) {
  37. int buf;
  38. buf = (code(message[i]) + code(key[i%key.length()]));
  39. if (buf >= 33) {
  40. over += '1';
  41. buf = buf % 33;
  42. }
  43. else over += '0';
  44. buf = buf % 33;
  45. cout << endl << code(message[i]) << ' ' << code(key[i%key.length()])<<' '<<buf;
  46. decode += alpha[buf];
  47. }
  48. cout << endl;
  49. cout << decode;
  50. cout << endl;
  51. for (int i = 0; i < message.length(); ++i)
  52. {
  53. int buf;
  54. int codeb= code(decode[i]);
  55. if (over[i] == '1') codeb += 33;
  56. buf = abs((codeb - code(key[i%key.length()]) )% 33);
  57. cout << endl << codeb << ' ' << code(key[i%key.length()]) << ' ' << buf;
  58. cout << alpha[buf];
  59. output << alpha[buf];
  60. }
  61. cout << endl;
  62. system("pause");
  63. return 0;
  64. }
Add Comment
Please, Sign In to add comment